from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'start' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): def creating_session(self): import itertools treat_type = itertools.cycle(['bA', 'nA', 'bB', 'nB']) for p in self.get_players(): p.treat_type = next(treat_type) if p.treat_type == 'bA' or p.treat_type == 'bB': p.treatment = 0 p.participant.vars['treatment'] = 0 else: p.treatment = 1 p.participant.vars['treatment'] = 1 if p.treat_type == 'bA' or p.treat_type == 'nA': p.participant.vars['type'] = 'A' else: p.participant.vars['type'] = 'B' class Group(BaseGroup): pass class Player(BasePlayer): treat_type = models.CharField() treatment = models.IntegerField() mturk_id = models.CharField(label="MTurk ID:") female = models.IntegerField(choices=[(0, "Male"), (1, "Female"), (2, "Non-binary")], # widget=widgets.RadioSelect, label="Please indicate your gender.") age = models.IntegerField(min=15, max=100, label="How old are you?") education = models.IntegerField(choices=[(1, "Haven't graduated high school."), (2, "GED"), (3, "High school graduate"), (4, "Currently in college"), (5, "Bachelors"), (6, "Masters"), (7, "Professional degree (JD, MD, MBA)"), (8, "Doctorate")], # widget=widgets.RadioSelect, label="What is your highest educational degree? If you cannot find your degree in the following list, please indicate which degree from the list is closest to your actual degree.") employment = models.IntegerField(choices=[(1, "Employed full-time"), (2, "Employed part-time"), (3, "Independent, or business owner"), (4, "Out of work, or seeking work"), (5, "Student"), (6, "Out of labor force (e.g. retired or parent raising one or more children)"), ], # widget=widgets.RadioSelect, label="What is your current employment status?") income = models.IntegerField(choices=[(1, "$0 - $9,999"), (2, "$10,000 - $14,999"), (3, "$15,000 - $19,999"), (4, "$20,000 - $29,999"), (5, "$30,000 - $39,999"), (6, "$40,000 - $49,999"), (7, "$50,000 - $74,999"), (8, "$75,000 - $99,999"), (9, "$100,000 - $124,999"), (10, "$125,000 - $149,999"), (11, "$150,000 - $199,999"), (12, "$200,000+") ], # widget=widgets.RadioSelect, label="How high was your total household income, before taxes, last year (2019)?") # state = models.CharField(label="In which state do you live?") state = models.IntegerField(choices=[(1, "Alabama"), (2, "Alaska"), (3, "American Samoa"), (4, "Arizona"), (5, "Arkansas"), (6, "California"), (7, "Colorado"), (8, "Connecticut"), (9, "Delaware"), (10, "District Of Columbia"), (11, "Federated States Of Micronesia"), (12, "Florida"), (13, "Georgia"), (14, "Guam"), (15, "Hawaii"), (16, "Idaho"), (17, "Illinois"), (18, "Indiana"), (19, "Iowa"), (20, "Kansas"), (21, "Kentucky"), (22, "Louisiana"), (23, "Maine"), (24, "Marshall Islands"), (25, "Maryland"), (26, "Massachusetts"), (27, "Michigan"), (28, "Minnesota"), (29, "Mississippi"), (30, "Missouri"), (31, "Montana"), (32, "Nebraska"), (33, "Nevada"), (34, "New Hampshire"), (35, "New Jersey"), (36, "New Mexico"), (37, "New York"), (38, "North Carolina"), (39, "North Dakota"), (40, "Northern Mariana Islands"), (41, "Ohio"), (42, "Oklahoma"), (43, "Oregon"), (44, "Palau"), (45, "Pennsylvania"), (46, "Puerto Rico"), (47, "Rhode Island"), (48, "South Carolina"), (49, "South Dakota"), (50, "Tennessee"), (51, "Texas"), (52, "Utah"), (53, "Vermont"), (54, "Virgin Islands"), (55, "Virginia"), (56, "Washington"), (57, "West Virginia"), (58, "Wisconsin"), (59, "Wyoming")], # widget=widgets.RadioSelect, label="In which state do you live?") ethnicity = models.IntegerField(choices=[(1, "Hispanic or Latino"), (2, "American Indian or Alaskan Native"), (3, "Asian"), (4, "Native Hawaiian or Other Pacific Islander"), (5, "Black or African American"), (6, "White"), ], # widget=widgets.RadioSelect, label="Which of the following best describes your race or ethnicity?") experience = models.IntegerField(label="How many hours per week do you spend online doing tasks for money?", min=0) attention = models.IntegerField(choices=[(1, "Option A: Probability 20% and $1.90"), (2, "Option B: Probability 30% and $1.80"), (3, "Option C: Probability 40% and $1.70"), (4, "Option D: Probability 50% and $1.60"), (5, "Option E: Probability 60% and $1.50"), (6, "Option F: Probability 70% and $1.40")], widget=widgets.RadioSelect, label="Please choose one option:") no_attention = models.BooleanField(initial=False) def role(self): if self.participant.vars['type'] == 'A': return 'A' else: return 'B'