oTree Forum >

Randomly assigning groups to treatments

#1 by nathanliang (edited )

To Whom It May Concern—

I'm running a psychology experiment where I have to assign groups of players to either participate in a "public" or a "private" public goods game. The idea is that I'd like to have Player 2 either see or not see the results of Player 1's decision as the dictator in a dictator game before playing a trust game with them. Crucially, Player 1 will also know whether they are being observed or not, so the instructions will also change depending on treatment condition for them. 

I'd like to be able to show different instructions on a given intro page along the (conceptual) lines of:

{{ if session (or subsession).public == True }} 
    <!-- my text -->
{{ else }}
    <!-- other text -->
{{ endif }}

Referencing previous forum posts and the documentation, I was led to write the below in my __init__.py file for the app where I have my economic games page sequences—the only difference from most others' posts is that I'm working on the group level (maybe this is incorrect?) instead of the player level.

class Subsession(BaseSubsession):
    def creating_session(subsession):
        import itertools
        conditions = itertools.cycle(['public', 'private'])
        for g in subsession.get_groups():
            g.public = next(conditions)

I'm not sure if this makes sense—many, many thanks in advance for your time and help!

#2 by nathanliang (edited )

(I think I'm having this same question but am struggling to implement your suggestion on a group as opposed to player level)

#3 by nathanliang

The question I meant to link: https://groups.google.com/g/otree/c/mcyMDrOGaLI/m/x-V9qngvCAAJ

Write a reply

Set forum username