oTree Forum >

randomize groups to different pages

#1 by pia

Hi all, 

I want to run an online experiment where I randomize players into groups of two and keep those groups constant over all rounds. For this I use: 
def creating_session(self):
    #match participants randomly in round 1
    if self.round_number == 1:
        self.group_randomly()
    else:
        self.group_like_round(1)

In round X I want the groups to be split in treatment and control group. The difference being them seeing different pages. And I still want to keep the groups the same since round1. 

I use: 
def creating_session2(subsession):
    import itertools pressure = itertools.cycle[(True, False)]
        if subsession.round_number == 3:
            for group in subsession.get_groups():
            group.page_chat = next(pressure)
 
class TreatmentWaitPage(WaitPage):
    def is_displayed(player: Player):
        return player.round_number == 3
        
    @staticmethod
    def after_all_groups_arrive(subsession):
        subsession.creating_session2()
 
and
class Chat2(Page):
    timeout_seconds = 300
    def is_displayed(player: Player):
        return ( 
            player.round_number == 4 and player.group.page_chat)
 
class Essay(Page):
    form_model = 'player'
    form_fields = ['essay']
    timeout_seconds = 300
 
    def is_displayed(player: Player):
        return ( 
            player.round_number == 4 and not player.group.page_chat)
 
and I set:
class Group(BaseGroup):
    page_chat = models.BooleanField()

This results in the error: 
TypeError: group.page_chat is None. Accessing a null field is generally considered an error.
and I also tried it without itertools and just random - same error occurs. 

If someone has a suggestion how to solve it I would appreciate that. 
Thank you.

Write a reply

Set forum username