from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random # to get random value author = 'Taemin Ko, Keith Wee Liang Shern and Yuki Fujita' doc = """ Distinguish risk-aversion between Asian and Non-Asian """ class Constants(BaseConstants): name_in_url = 'risk_aversion' players_per_group = None num_rounds = 10 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): gender = models.StringField( choices=[('Male'), ('Female')], label='Are you male or female?', widget=widgets.RadioSelect) age = models.IntegerField( label='What is your age?', min=18, max=100) # this question is for the case that age could have an effect on risk-aversion, # so other distracting factors can be removed with the data (excludability) identification = models.StringField( choices=[('Asian'), ('Non-Asian')], # to divide participants in two group, treatment and control label='Are you Asian or Non-Asian?', # Treatment: Asian, Control, Non-Asian widget=widgets.RadioSelect) country = models.StringField( label='Where did you grow up?') # there is an additional question about birthplace # because there are some asian students who were not born in an asian counrty # and their behavior might be different from the one of asian students who grew up in an asian country lottery = models.StringField( choices=[('Yes'), ('No')], label='Do you want to join the game?', widget=widgets.RadioSelect) probability = models.IntegerField() def set_payoffs(self): py = self.get_player_by_role('player') self.probability = random.randint(0, 1) # to make the probability 50 % (0 or 1 => 1/2) if self.lottery == 'Yes': # take part in the lottery game if self.probability == 1: # if random number is 1 a participant will win the game (50%) py.payoff = 10 * self.round_number else: # if random number is not 1, a participant will lose the game (50%) py.payoff = -1 * (self.round_number ** 2) # every round this game become riskier # participants can skip rounds if they choose no in lottery choice. it is made in pages.py