Introduction to z-tree: Day 2 Andrew W. Bausch NYU Department of Politics bausch@nyu.edu January 10, 2012 Andrew W. Bausch January 10, 2012 1 / 27
Overview: Interactive Games Individual decision making experiments Subject s payoffs only depend on subject s own decisions Programs in the treatment only process information of a single subject Interactive experiments Payoffs of a subject also depend on the behavior of other subjects Programs have to access information from records of other subjects Andrew W. Bausch January 10, 2012 2 / 27
Overview: Interactive Games Matching Scope Operator & the same function Programming an experiment with interaction Andrew W. Bausch January 10, 2012 3 / 27
Matching Random Partner Matching In interactive experiments subjects are assigned into groups and the game is played repeatedly over several rounds Who interacts with whom in a given round? z-tree has built-in functions, but just as easy to do it yourself and you retain more control Andrew W. Bausch January 10, 2012 4 / 27
Matching Random Partner Matching In the first stage, create a one-line Program in the Subjects Table randgroup = random(); This generates a random number that we will use to create the groups End this program so the subjects can access each other s randgroup Andrew W. Bausch January 10, 2012 5 / 27
Matching Random Partner Matching continued Create a second Program in the Subjects Table right below the first Define GroupSize in Background ranking = count(randgroup >= : randgroup); ranking = ranking - 1; GroupNum = rounddown(ranking / GroupSize,1); We rank each subjects random number and make groups based on the ranking Andrew W. Bausch January 10, 2012 6 / 27
Matching Keeping the Same Groups Start with the same two programs as above wrap if(period == 1) around those programs in the second program, put an else statement else{ GroupNum= OLDsubjects.find(same(Subject), GroupNum); } z-tree normally only allows access the value of variables from the Subject s current period Use the OLDsubjects.find function to get each subject s previous value of GroupNum and passing it forward to the current round If we do this every round, the subjects keep the same GroupNum throughout the experiment Andrew W. Bausch January 10, 2012 7 / 27
Scope Operator Main Use Getting information from other subjects The scope operator is a colon : But, easier to read if you use the same function I primarily use the colon when applying a function ranking = count(randgroup >=: randgroup); Andrew W. Bausch January 10, 2012 8 / 27
same Function Passing Information between players Groupaverage = average(same(group), Contribution); Gets all contributions from a subjects group and uses the average function to calculate the group average Passing Information specific information from a player Choice3 = find(same(groupnum)&playernum == 3, Choice); Finds Player 3 in this subject s group and assigns Player 3 s Choice to a variable called Choice3 for all subjects You can create player numbers similar to the way we assigned groups Andrew W. Bausch January 10, 2012 9 / 27
The guessing game (beauty contest) Nagel, R. (1995). Unraveling in guessing games: An experimental study. American Economic Review, 85(5), 1313-1326. Andrew W. Bausch January 10, 2012 10 / 27
The guessing game 6 subjects (2 groups of 3 subjects) Keep the same group throughout Subjects enter a number between 0 and 100 Subject closest to 2/3 of the group s average entry wins a prize of 60 points In case of a tie, the prize is shared equally among the winning group members Continue for 10 rounds Andrew W. Bausch January 10, 2012 11 / 27
Background variables Declare the variables we don t plan on changing by creating a new program under Background I keep them all in the subjects table Andrew W. Bausch January 10, 2012 12 / 27
Setting up Groups Andrew W. Bausch January 10, 2012 13 / 27
Getting a Random Number if(period ==1) { randgroup = random(); } Assigning the Groups if(period == 1) { ranking = count(randgroup >= : randgroup); ranking = ranking - 1; GroupNum = rounddown(ranking / GroupSize,1); } else { GroupNum = OLDsubjects.find(same(Subject), GroupNum); } Note: These must be in two separate programs Andrew W. Bausch January 10, 2012 14 / 27
Set the Active Screen for Stage 1 Can copy and paste from yesterday Minimum input is 0 Maximum input is 100 Andrew W. Bausch January 10, 2012 15 / 27
Get the Group Average Note that we are going to need to use three separate short programs Andrew W. Bausch January 10, 2012 16 / 27
Get the Group Average // Get the group average Groupaverage=average(same(GroupNum), guess); // find 2/3s of it twothirdsgroupave = Groupaverage*2/3; // Calculate the difference Diff = abs(guess - twothirdsgroupave); Andrew W. Bausch January 10, 2012 17 / 27
Calculate the lowest difference Andrew W. Bausch January 10, 2012 18 / 27
Calculate the lowest difference // Calculate the lowest difference for the group Best = minimum( same(groupnum), Diff); // See if this subject is the winner Winner = if(diff == Best, 1, 0); Andrew W. Bausch January 10, 2012 19 / 27
Find the Payoffs Andrew W. Bausch January 10, 2012 20 / 27
Find the Payoffs // Determine how many winners NumWinners = sum(same(groupnum), Winner); // Set the round payoff using the number of winners and //the Winner variable RoundPayoff = Prize*Winner / NumWinners; Andrew W. Bausch January 10, 2012 21 / 27
Conditional Displays We want to tell each subject is she won Add New Plot Text Set Display Condition Winner == 1 <> You won! You were one of < NumWinners 1 > winners Andrew W. Bausch January 10, 2012 22 / 27
Conditional Displays Or lost Add New Plot Text Set Display Condition Winner == 1 You Lost! Andrew W. Bausch January 10, 2012 23 / 27
Displaying the Payoff Add New Plot Text <> Your Payoff this round is < RoundPayoff.1 > Andrew W. Bausch January 10, 2012 24 / 27
Stage 1 Andrew W. Bausch January 10, 2012 25 / 27
Stage 2: Winners Andrew W. Bausch January 10, 2012 26 / 27
Stage 2: Losers Andrew W. Bausch January 10, 2012 27 / 27