Philipp Chapkovski European University Institute o Tree workshop

  • Slides: 22
Download presentation
Philipp Chapkovski European University Institute o. Tree workshop University of Hamburg May 29 -30,

Philipp Chapkovski European University Institute o. Tree workshop University of Hamburg May 29 -30, 2018 Day 2

Task: • Create two different treatments of Public Good game: • 1. Baseline treatment

Task: • Create two different treatments of Public Good game: • 1. Baseline treatment • 2. Treatment with heterogeneous endowments (each player has his/her own randomly generated endowment).

Updated constants: • class Constants(Base. Constants): name_in_url = 'pgg' players_per_group = 3 num_rounds =

Updated constants: • class Constants(Base. Constants): name_in_url = 'pgg' players_per_group = 3 num_rounds = 2 endowment = 100 multiplier = 2 min_endowment = 10 max_endowment = 100

Updated Player model: • class Player(Base. Player): endowment = models. Integer. Field() contribution =

Updated Player model: • class Player(Base. Player): endowment = models. Integer. Field() contribution = models. Integer. Field()

Creating session: • import random class Subsession(Base. Subsession): def creating_session(self): for p in self.

Creating session: • import random class Subsession(Base. Subsession): def creating_session(self): for p in self. get_players(): if self. round_number == 1: p. endowment = random. randint(Constants. min_endowment, Constants. max_endowment) else: p. endowment = p. in_round(1). endowment

Dynamic max contribution • class Contribution(Page): form_model = 'player' form_fields = ['contribution'] def contribution_max(self):

Dynamic max contribution • class Contribution(Page): form_model = 'player' form_fields = ['contribution'] def contribution_max(self): return self. player. endowment

Resulting data

Resulting data

Updated results page • >h 5>Other participants: </h 5> <table class="table-bordered"> <thead class="table-info"> <tr>

Updated results page • >h 5>Other participants: </h 5> <table class="table-bordered"> <thead class="table-info"> <tr> <th>Id: </th> <th>Endowment: </th> <th>Contribution: </th> </tr> </thead> {% for i in player. get_others_in_group %} <tr> <td> {{ i. id_in_group }}</td> <td> {{ i. endowment }}</td> <td> {{ i. contribution }}</td> </tr> {% endfor %} </table<

Updated results page

Updated results page

Creating different treatments • SESSION_CONFIGS = [ { 'name': 'pgg_baseline', 'display_name': "Public Good Game:

Creating different treatments • SESSION_CONFIGS = [ { 'name': 'pgg_baseline', 'display_name': "Public Good Game: baseline", 'num_demo_participants': 3, 'app_sequence': ['pgg'], }, { 'name': 'pgg_hetero', 'display_name': "Public Good Game: heterogeneous endowment", 'num_demo_participants': 3, 'app_sequence': ['pgg'], 'hetero': True, }, ]

Different treatments: updated code • import random class Subsession(Base. Subsession): def creating_session(self): if self.

Different treatments: updated code • import random class Subsession(Base. Subsession): def creating_session(self): if self. session. config. get('hetero'): for p in self. get_players(): if self. round_number == 1: p. endowment = random. randint(Constants. min_endowment, Constants. max_endowment) else: p. endowment = p. in_round(1). endowment else: for p in self. get_players(): p. endowment=Constants. endowment

Passing information between apps • Let’s create another app, where we collect info about

Passing information between apps • Let’s create another app, where we collect info about a gender of participants. • We later on will show it in some treatments on Contribution page

Creating a ‘Gender’ app • otree startapp gender • creating a session config with

Creating a ‘Gender’ app • otree startapp gender • creating a session config with ‘gender’: • { 'name': 'pgg_gender', 'display_name': "Public Good Game: gender treatment", 'num_demo_participants': 3, 'app_sequence': ['gender', 'pgg'], },

Creating a ‘Gender’ app • in models. py of new ‘Gender’ app: • class

Creating a ‘Gender’ app • in models. py of new ‘Gender’ app: • class Player(Base. Player): gender = models. String. Field(choices=['Male', 'Female'], widget=widgets. Radio. Select. Horizontal)

Creating a ‘Gender’ app • templates: • {% block content %} {% formfield player.

Creating a ‘Gender’ app • templates: • {% block content %} {% formfield player. gender label='What is your gender? ' %} {% next_button %} {% endblock %}

Creating a ‘Gender’ app • in pages. py of new ‘Gender’ app: class Gender(Page):

Creating a ‘Gender’ app • in pages. py of new ‘Gender’ app: class Gender(Page): form_model = 'player' form_fields = ['gender'] def before_next_page(self): self. participant. vars['gender'] = self. player. gender page_sequence = [ Gender, ]

Showing gender info on Contribution

Showing gender info on Contribution

Showing gender info on Contribution • >h 4>Info about other participants: </h 4> <table

Showing gender info on Contribution • >h 4>Info about other participants: </h 4> <table class="table-bordered"> <thead class="table-info"> <tr> <th>Id: </th> <th>Endowment: </th> <th>Gender: </th> </tr> </thead> {% for i in player. get_others_in_group %} <tr> <td> {{ i. id_in_group }}</td> <td> {{ i. endowment }}</td> <td> {{ i. participant. vars. gender }}</td> </tr> {% endfor %} </table<

Making groups homogenous • Our task: • based on the gender of a participant

Making groups homogenous • Our task: • based on the gender of a participant match them into groups of • men only • women only

Making groups homogenous • { }, 'name': 'pgg_gender_monogender', 'display_name': "Public Good Game: mono gender",

Making groups homogenous • { }, 'name': 'pgg_gender_monogender', 'display_name': "Public Good Game: mono gender", 'num_demo_participants': 3, 'app_sequence': ['gender', 'pgg'], 'mono': True,

Making groups homogenous • Creating a new Waiting Page in the beginning of page_sequence

Making groups homogenous • Creating a new Waiting Page in the beginning of page_sequence • class Matching. WP(Wait. Page): group_by_arrival_time = True def is_displayed(self): return self. session. config. get('mono') and self. round_number == 1 def get_players_for_group(self, waiting_players): c = Constants. players_per_group women = [p for p in waiting_players if p. participant. vars. get('gender') == 'Female'] men = [p for p in waiting_players if p. participant. vars. get('gender') == 'Male'] if len(women) >= c: return women[: c] if len(men) >= c: return men[: c]

What if there is no match? • class Matching. WP(Wait. Page): group_by_arrival_time = True

What if there is no match? • class Matching. WP(Wait. Page): group_by_arrival_time = True def is_displayed(self): self. participant. vars['arrived'] = True return self. session. config. get('mono') and self. round_number == 1 def get_players_for_group(self, waiting_players): …. # previous code is here! already_passed = [p for p in self. session. get_participants() if p. vars. get('arrived')] if len(already_passed) == self. session. num_participants: return waiting_players