from otree.api import * import random doc = """ Behavioural Economics classroom experiments (LUT 2023) """ class C(BaseConstants): NAME_IN_URL = 'behavioural_econ' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 """ Experiments: 1. Limits of rationality a) Linda problem (LR1) b) Anchoring (LR2) c) Anchoring (LR3) d) Anchoring (LR3_2) e) Anchoring (LR3_3) d) Framing (LR4) e) Tom W (LR6) f) English language (LR7) g) h) 3. Risk and uncertainty: a) Savouring (RU1) b) Allais paradox (RU2) c) BRET/CCT (RU3) d) Prospect theory (RU4) e) Lottery with framing (RU5) f) Ellsberg's paradox (RU6) g) St.Petersburg paradox (RU7) """ class Subsession(BaseSubsession): pass def creating_session(subsession): if subsession.round_number == 1: for player in subsession.get_players(): participant = player.participant participant.treatment = subsession.session.config['TREATMENT'] # participant.treatment = "RU2" class Group(BaseGroup): pass class Player(BasePlayer): age = models.IntegerField(min=1920, max=2006) sex = models.StringField(widget=widgets.RadioSelect, choices=["Male", "Female", "I prefer not to say"]) LR1_1 = models.IntegerField(label='Linda is a teacher in elementary school') LR1_2 = models.IntegerField(label='Linda works in a bookstore and takes Yoga classes') LR1_3 = models.IntegerField(label='Linda is active in the feminist movement') LR1_4 = models.IntegerField(label='Linda is a psychiatric social worker') LR1_5 = models.IntegerField(label='Linda is a member of the League of Women Voters') LR1_6 = models.IntegerField(label='Linda is a bank teller') LR1_7 = models.IntegerField(label='Linda is an insurance salesperson') LR1_8 = models.IntegerField(label='Linda is a bank teller and is active in the feminist movement') treatment_LR2 = models.IntegerField() LR2_answer = models.IntegerField(label="Provide your answer below.") LR3_number = models.IntegerField() LR3_answer_1 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[0, 'Greater than'], [1, 'Smaller than']], label="") LR3_answer_2 = models.IntegerField() LR3_2_scenario = models.IntegerField() LR3_2_answer = models.IntegerField(label="How long is the river Nile in kilometers?") LR4_scenario = models.IntegerField() LR4_answer = models.IntegerField(choices=[[1, 'Program A'], [2, 'Program B']], widget=widgets.RadioSelect, label="") LR5_scenario = models.IntegerField() LR5_answer_1 = models.IntegerField(widget=widgets.RadioSelect, choices=[[0,"A: a sure gain of $240"], [1, 'B: 25% chance to gain $1000 and 75% chance to gain nothing.']]) LR5_answer_2 = models.IntegerField(widget=widgets.RadioSelect, choices=[[0, "C: a sure loss of $750"], [1, 'D: 75% chance of losing $1000 and a 25% chance to lose nothing.']]) LR5_answer_3 = models.IntegerField(widget=widgets.RadioSelect, choices=[[0,'E: 25% chance to win $240 and 75% chance to lose $760.'], [1, 'F: 25% chance to win $250 and 75% chance to lose $750.']]) LR6_scenario = models.IntegerField() LR6_answer_1_1 = models.IntegerField(label="Business administration") LR6_answer_1_2 = models.IntegerField(label="Computer science") LR6_answer_1_3 = models.IntegerField(label="Engineering") LR6_answer_1_4 = models.IntegerField(label="Humanities and education") LR6_answer_1_5 = models.IntegerField(label="Law") LR6_answer_1_6 = models.IntegerField(label="Library science") LR6_answer_1_7 = models.IntegerField(label="Medicine") LR6_answer_1_8 = models.IntegerField(label="Physical and life sciences") LR6_answer_1_9 = models.IntegerField(label="Social science and social work") LR7_scenario = models.IntegerField() LR7_answer1 = models.IntegerField(choices=[[0, 'A'], [1, 'B']], label='More likely is option:') LR7_answer2 = models.IntegerField(choices=[[0, 'A'], [1, 'B']], label='More likely is option:') LR7_answer3 = models.IntegerField(choices=[[0, 'A'], [1, 'B']], label='More likely is option:') LR7_answer4 = models.IntegerField(choices=[[0, 'A'], [1, 'B']], label='More likely is option:') LR8_scenario = models.IntegerField() LR8_answer = models.IntegerField(choices=[[0, 'Choose between A and B'], [1, 'Add another lottery']], label="I choose") RU2_answer_1 = models.IntegerField(widget=widgets.RadioSelect, choices=[[0, "Gamble A"], [1, "Gamble B"]], label="Which one would you choose?") RU2_answer_2 = models.IntegerField(widget=widgets.RadioSelect, choices=[[0, "Gamble C"], [1, "Gamble D"]], label="Which one would you choose?") RU3_answer_1 = models.IntegerField(widget=widgets.RadioSelect, choices=[[0, "Option A"], [1, "Option B"]], label="Which one would you choose?") RU3_answer_2 = models.IntegerField(widget=widgets.RadioSelect, choices=[[0, "Option A"], [1, "Option B"]], label="Which one would you choose?") RU4_answer_1 = models.IntegerField(widget=widgets.RadioSelect, choices=[[0, "Option A"], [1, "Option B"]], label="Which one would you choose?") RU4_answer_2 = models.IntegerField(widget=widgets.RadioSelect, choices=[[0, "Option C"], [1, "Option D"]], label="Which one would you choose?") RU6_1_answer = models.IntegerField(widget=widgets.RadioSelect, choices=[[0, "I"], [1, "II"]], label="Which action do you choose?") RU6_2_answer = models.IntegerField(widget=widgets.RadioSelect, choices=[[0, "I"], [1, "II"]], label="Which action do you choose?") RU7_answer = models.IntegerField(label="Now, how much would you pay to play this game? Pick a number!") input_L1 = models.CurrencyField() input_L2 = models.CurrencyField() input_L3 = models.CurrencyField() input_L4 = models.CurrencyField() input_L5 = models.CurrencyField() input_L6 = models.CurrencyField() input_L7 = models.CurrencyField() input_L8 = models.CurrencyField() input_L9 = models.CurrencyField() input_L10 = models.CurrencyField() input_L11 = models.CurrencyField() input_L12 = models.CurrencyField() input_L13 = models.CurrencyField() input_L14 = models.CurrencyField() input_L15 = models.CurrencyField() input_L16 = models.CurrencyField() input_L17 = models.CurrencyField() input_L18 = models.CurrencyField() input_L19 = models.CurrencyField() input_L20 = models.CurrencyField() input_L21 = models.CurrencyField() input_L22 = models.CurrencyField() input_L23 = models.CurrencyField() input_L24 = models.CurrencyField() input_L25 = models.CurrencyField() # PAGES class Start(Page): def before_next_page(player: Player, timeout_happened): number = [65, 10] # 1 = 1x2x3x4x5x6x7x8 # 2 = 8x7x6x5x4x3x2x1 player.LR3_number = random.choice(number) scenario = [1, 2] # 1 = survival format # 2 = mortality format player.LR4_scenario = random.choice(scenario) player.LR5_scenario = random.choice(scenario) scenario2 = [1,2,3] player.LR6_scenario = random.choice(scenario2) player.LR7_scenario = random.choice(scenario) player.LR8_scenario = random.choice(scenario) player.LR3_2_scenario = random.choice(scenario) class LR1(Page): def is_displayed(player: Player): return player.participant.treatment == "LR1" form_model = 'player' form_fields = ['LR1_1', 'LR1_2', 'LR1_3', 'LR1_4', 'LR1_5', 'LR1_6', 'LR1_7', 'LR1_8'] class LR2_1(Page): def is_displayed(player: Player): return player.participant.treatment == "LR2" def before_next_page(player: Player, timeout_happened): group = [1, 2] # 1 = 1x2x3x4x5x6x7x8 # 2 = 8x7x6x5x4x3x2x1 player.treatment_LR2 = random.choice(group) class LR2_2(Page): def is_displayed(player: Player): return player.participant.treatment == "LR2" form_model = 'player' form_fields = ['LR2_answer'] timeout_seconds = 6 class LR3_1(Page): def is_displayed(player: Player): return player.participant.treatment == "LR3" form_model = 'player' form_fields = ['LR3_answer_1', 'LR3_answer_2'] class LR3_2(Page): def is_displayed(player: Player): return player.participant.treatment == "LR3_2" form_model = 'player' form_fields = ['LR3_2_answer'] class LR4(Page): def is_displayed(player: Player): return player.participant.treatment == "LR4" form_model = 'player' form_fields = ['LR4_answer'] class LR5_1(Page): def is_displayed(player: Player): return player.participant.treatment == "LR5" and player.LR5_scenario == 1 form_model = 'player' form_fields = ['LR5_answer_1', 'LR5_answer_2'] class LR5_2(Page): def is_displayed(player: Player): return player.participant.treatment == "LR5" and player.LR5_scenario == 2 form_model = 'player' form_fields = ['LR5_answer_3'] class LR6_1(Page): def is_displayed(player: Player): return player.participant.treatment == "LR6" and player.LR6_scenario == 1 form_model = 'player' form_fields = ['LR6_answer_1_1', 'LR6_answer_1_2', 'LR6_answer_1_3', 'LR6_answer_1_4', 'LR6_answer_1_5', 'LR6_answer_1_6', 'LR6_answer_1_7', 'LR6_answer_1_8', 'LR6_answer_1_9'] class LR6_2(Page): def is_displayed(player: Player): return player.participant.treatment == "LR6" and player.LR6_scenario == 2 form_model = 'player' form_fields = ['LR6_answer_1_1', 'LR6_answer_1_2', 'LR6_answer_1_3', 'LR6_answer_1_4', 'LR6_answer_1_5', 'LR6_answer_1_6', 'LR6_answer_1_7', 'LR6_answer_1_8', 'LR6_answer_1_9'] class LR6_3(Page): def is_displayed(player: Player): return player.participant.treatment == "LR6" and player.LR6_scenario == 3 form_model = 'player' form_fields = ['LR6_answer_1_1', 'LR6_answer_1_2', 'LR6_answer_1_3', 'LR6_answer_1_4', 'LR6_answer_1_5', 'LR6_answer_1_6', 'LR6_answer_1_7', 'LR6_answer_1_8', 'LR6_answer_1_9'] class LR7(Page): def is_displayed(player: Player): return player.participant.treatment == "LR7" form_model = 'player' form_fields = ['LR7_answer1'] class LR7_2(Page): def is_displayed(player: Player): return player.participant.treatment == "LR7" form_model = 'player' form_fields = ['LR7_answer2'] class LR7_3(Page): def is_displayed(player: Player): return player.participant.treatment == "LR7" form_model = 'player' form_fields = ['LR7_answer3'] class LR7_4(Page): def is_displayed(player: Player): return player.participant.treatment == "LR7" form_model = 'player' form_fields = ['LR7_answer4'] class LR8(Page): def is_displayed(player: Player): return player.participant.treatment == "LR8" form_model = 'player' form_fields = ['LR8_answer'] class RU1_1(Page): def is_displayed(player: Player): return player.participant.treatment == "RU1" form_model = 'player' form_fields = ['input_L1', 'input_L2', 'input_L3', 'input_L4', 'input_L5', 'input_L6', 'input_L7', 'input_L8', 'input_L9', 'input_L10', 'input_L11', 'input_L12', 'input_L13', 'input_L14', 'input_L15', 'input_L16', 'input_L17', 'input_L18', 'input_L19', 'input_L20', 'input_L21', 'input_L22', 'input_L23', 'input_L24', 'input_L25'] class RU2_1(Page): def is_displayed(player: Player): return player.participant.treatment == "RU2" form_model = 'player' form_fields = ['RU2_answer_1'] class RU2_2(Page): def is_displayed(player: Player): return player.participant.treatment == "RU2" form_model = 'player' form_fields = ['RU2_answer_2'] class RU4_1(Page): def is_displayed(player: Player): return player.participant.treatment == "RU4" form_model = 'player' form_fields = ['RU4_answer_1'] class RU4_2(Page): def is_displayed(player: Player): return player.participant.treatment == "RU4" form_model = 'player' form_fields = ['RU4_answer_2'] class RU6_1(Page): def is_displayed(player: Player): return player.participant.treatment == "RU6" form_model = 'player' form_fields = ['RU6_1_answer'] class RU6_2(Page): def is_displayed(player: Player): return player.participant.treatment == "RU6" form_model = 'player' form_fields = ['RU6_2_answer'] class RU7(Page): def is_displayed(player: Player): return player.participant.treatment == "RU7" form_model = 'player' form_fields = ['RU7_answer'] class Demographics(Page): form_model = 'player' form_fields = ['age', 'sex'] class Final(Page): pass page_sequence = [ Start, LR1, LR2_1, LR2_2, LR3_1, LR3_2, LR4, LR5_1, LR5_2, LR6_1, LR6_2, LR6_3, LR7, LR7_2, LR7_3, LR7_4, LR8, RU1_1, RU2_1, RU2_2, RU4_1, RU4_2, RU6_1, RU6_2, RU7, # Demographics, Final ]