oTree Forum >

Role assignment to a fraction of participants

#1 by Sahar (edited )

Hi all,
For my experiment I need to create a role for my participants and create a fraction of these participants assigned to another role. That is, I would like to have 300 participants, 200 of them assigned to a police role and 100 to citizen role (2/3 of all participants to police and 1/3 to citizen). Is that possible in otree? and how I can do that? 


#2 by Chris_oTree

This is one way to do it:

def creating_session(subsession):
    import itertools
    treatments = itertools.cycle([True, False, False])
    for player in subsession.get_players():
        player.is_police = next(treatments)
Though check this link to understand the alternatives: https://otree.readthedocs.io/en/latest/treatments.html

Also consider, is it one big group with 300 participants? (That's what I coded above.) Or it's 100 groups, each with 1 police and 2 citizens?

#3 by Sahar

Both can work, I guess. What I need is to have two citizens for each police. It does not matter whether they are in a group or not. 
The code you provide works however I do not know where I can see which role they are allocated into.


#4 by Chris_oTree

You need to define a player field to store this:

is_police = models.BooleanField()

Then you will see it in the data table in the admin, etc.

#5 by Sahar

Yes, there is a field to store it, but nothing stored. How can I try the second option like have groups of three participants and one has police and the other two have citizen roles? I know how to assign them to two separated roles but not three roles which two of them are similar.


Write a reply

Set forum username