oTree Forum >

AttributeError: 'Participant' object has no attribute 'treatment'

#1 by ParetoDeficiente

I want to design a two-round bank run experiment with two banks: A and B. I designed it as depositors from bank A being the treatment group. So...

First, I added a participant field in settings:

    "PARTICIPANT_FIELDS = ['treatment']"

Second, I set 2 rounds and, e.g., 10 players by group. In addition, I created two constants called "A_WITHDRAWALS" and "B_WITHDRAWALS", both integers.

Third, I created a treatment group (they will be depositors from bank A while the control will be depositors from bank B) in subsession such that the players are the same across rounds (i.e., participants):

    def creating_session(subsession):
        import random
        if subsession.round_number == 1:
            for player in subsession.get_players():
                participant = player.participant 
                participant.treatment = random.choice(['Bank A', 'Bank B'])
Fourth, I created the following function in Group:

    def set_payoffs(group):
        players = group.get_players()
        A_WITHDRAWALS = []
        B_WITHDRAWALS = []
        for p in players:
            if p.treatment == 'Bank A':
Fifth, I created a boolean field in Player called "withdrawal" such that if the player answer 'Yes', they withdraw their money from the bank. Otherwise, they do not withdraw.

Finally, in the first page I wrote:

    <p> You are a depositor from {{ treatment }}. </p>

However, I got the following error: AttributeError: 'Participant' object has no attribute 'treatment'

If I delete the aforementioned sentence, the game runs perfectly. What is left? Maybe I need another field in Player?

Write a reply

Set forum username