from otree.api import * import random doc = """ Risk attitude elicitation. Participants choose 1 out of 6 available lotteries with 50 percent chance of High (H) or Low (L) outcome. The options vary in their Expected Return (ER) and Standard Deviation (SD), giving us a range for the CRRA parameter implied by the choice. The first option has no risk, H = L Based on the parameters chosen for the experiment, we would expect those who choose the first lottery to also never join a cartel. Those who join the second would join a cartel in all treatments, but produce more than optimal quantity to limit the implied fine. Third implies joining and producing optimal quantity in the overcharge-regime cartel, but more in profit and revenue. Fourth implies joining and producing optimal quantity in profit regime, more in revenue (and perhaps deviation in overcharge?) Fifth implies joining and producing optimal quantity in revenue regime (and perhaps deviation in profit and overcharge?) Sixth has same ER as fifth, but higher SD, implying a negative CRRA parameter and risk-seeking preferences (expected to always deviate?). """ class C(BaseConstants): NUM_GAMBLES = 6 OUTCOMES = { 1: {'Low': 225, 'High': 225}, 2: {'Low': 210, 'High': 270}, 3: {'Low': 175, 'High': 330}, 4: {'Low': 130, 'High': 400}, 5: {'Low': 100, 'High': 450}, 6: {'Low': 10, 'High': 540} } NUM_OUTCOMES = len(OUTCOMES) NAME_IN_URL = 'risk_attitudes' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): chosen_gamble = models.IntegerField( choices=range(1, C.NUM_GAMBLES + 1), label='Please choose one of the following gambles:' ) outcome_received = models.StringField() amount_received = models.CurrencyField() def set_payoff(self): chosen_gamble = self.chosen_gamble if random.random() < 0.5: self.payoff = C.OUTCOMES[chosen_gamble]['High'] self.outcome_received = 'High' self.amount_received = self.payoff else: self.payoff = C.OUTCOMES[chosen_gamble]['Low'] self.outcome_received = 'Low' self.amount_received = self.payoff # PAGES class Lottery_Choice(Page): form_model = 'player' form_fields = ['chosen_gamble'] def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) gambles = [] for gamble_number, OUTCOMES in C.OUTCOMES.items(): gamble = { 'number': gamble_number, 'outcomes': OUTCOMES } gambles.append(gamble) context['gambles'] = gambles return context def before_next_page(self, timeout_happened): self.set_payoff() class Lottery_Outcome(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return { 'outcome_received': self.outcome_received, 'amount_received': self.amount_received, } page_sequence = [Lottery_Choice, Lottery_Outcome]