by Urs Fischbacher

Univerity of Zurich Department of Economics

 

About z-Tree
How to get z-Tree ?
Compatibility
Docu and Support
z-Tree Wiki
Tips & Tricks
Treatments
Papers
News & Versions
Known Bugs
Links




















  z-Tree:Tips and Tricks


Calculation of Rank

If you wish to determine for a record at which place the value of a variable x is situated relative to the others, you can define a formula.  The record with the greatest x shall be given a 1.
If all x are different or we accept that several x may have the same rank:
Rank = count ( x > = :x);
If x is an integer and we wish to have a different rank for each x, we add a random number to x and calculate the rank of this number.  We may not thereby integrate the random function into the sum formula, as we would then get an inconsistent ranking order.
x1 = x + random() / 2;
//---------- in a new program
Rank = count ( x1 > = :x1);
Note: When we write these two lines into one program, the variable x1 of the others is not yet calculated when we use it in the rank formula.  A simple trick consists of filling the random number into a field at the very beginning of the procedure.
We thus set
random1 = random();
in a program of the background
Now we can define the rank:
Rank = = count ( x + random1 > = :x + :random1);
top of page

Differing Endowments

You define a variable
Lumpsum = 0;
This variable can be changed in the specific parameters.
Under certain circumstances the profit should not contain the lump-sum payment.  This means that you define and set a variable ShownProfit
Profit = if( Period == 1, ShownProfit + Lumpsum, ShownProfit);ShownsTotalProfit = TotalProfit - Lumpsum;
top of page

Displaying the Number of Players that Have not yet Finished

First you define a variable in the globals table, e.g., NumPlayersWorking, and set the variable at the number of players that still have entries to make.  If all players still have entries to make, you write:

NumPlayersWorking = subjects.count();

Next you add the following program for the globals table to the OK button.

NumPlayersWorking = NumPlayersWorking -1;

NumPlayersWorking is automatically updated and may be displayed anywhere.

top of page

Payment of a Random Period

An experimental technique to avoid income effects consists in paying one randomly selected period.  To do this with z-Tree you have to store the profits of all the periods in the summary table.
You need the following program in the summary table:
array Profits[]; // one array element per subject
subjects.do {
 :Profits[ Subject ] = Profit;
 Profit = 0; // delete Profit, otherwise it is added up
 if ( Period == NumPeriods ) {
  SelectedPeriod = RandomPeriod;
  Profit = summary.find(
   Period == :SelectedPeriod,
   Profits[ :Subject ] );
 }
}
The variable SelectedPeriod can be set at a subject's screen after a dice has determined the paid period. If you want to pay a random period out of periods not played in the same same treatment, you have to define user defined tables. See
A table that survives the end of a treatment: The session table and User defined tables
top of page

I read in the manual that it should be possible to import parameters from a *.txt file set up elsewhere. What is the format of such a file, and how to import it? Also, can this importing include the subject groups, or just the variables?

You can import variable values one by one:
  • Open the parameter table.
  • Menu "Treatment/Import Variable Table"
    • Enter the name of the variable.
    • Select the file that contains the values. It must be tab separated; periods in lines and subjects in columns.
You can import any variable - also the Group variable.
top of page

Leave Profit Display Standing

You can also show the same information as on the active screen on the waiting screen.  You only have to remove the . continue. button.
top of page

Display Costs Table

If you wish to show the subjects a table with values, you make a grid box.  It is easiest to define an array that contains the function values.
 
top of page

Own Records at the Top of a List

If you want to place the own records of a subject at the top of a list, you can insert an expression into the sorting field of the contract list box.  Suppose you want to start with the records where you are the seller.  In these records, the variable Seller has the value of your variable Subject.  This can be expressed with the following expression:
if( Seller == :Subject , 0, 1)
Please note the use of the scope operator: It accesses the record of the subject that is in front of the screen that is set up.
top of page

How can I check whether a field is empty or not ?

If I try to make a check as follows
a_geb=="" // a_geb is the name of the variable
I get a "Syntax error".

You have to set the value of the variable to an illegal value. Since in z-Tree, only numbers are allowed as variables, this must be a number. Assume that the subjects have to enter a number between 0 and 23. In this case, you can use (for instance) -1 for empty. After the entry has been made, you can check if the variable still has the value -1.
This procedure does of course not work if your item is defined in a contract creation box. In this case, the variable cannot be set to an illegal value because the record containing the variable will only be constructed when you click at the button. In this case, you have to enter the "illegal value" into the field "Default" in the item dialog.

top of page

Why do the message boxes for range checks always appear in German ?

The range checks are built into zLeaf. They are currently available in German, English, French or Italian. For my convenience, the default is German. To start zLeaf in english you create (in Windows) a shortcut to zleaf.exe. You open the properties of the shortcut and change the "target" in the tab shortcut to
zleaf.exe /language english
Then, instead of starting zleaf directly, you start this shortcut and all texts will appear in English.
top of page

Multiphase Experiment

If a period in an experiment consists of several phases, you define the appropriate number of stages for each phase.  If a phase should be very complex, it is generally easier to define each phase as one period.
You define a variable Phase.  This variable is calculated at the beginning of a period.  If, for example, we have 2 periods
Phase = mod( Period-1, 2) +1
calculates the phase and
UserPeriod = rounddown( Period/2 );
calculates the period as it is supposed to be shown to the subjects.  This variable cannot appear in a normal header box.  However, you may insert it in a normal standard box (this also holds for the variable Period).
top of page

Why do subject PCs not connect to the experimenter PC? It says it can not create a socket.

To connect with the experimenter PC, the zLeaves have to know the IP number of it. There are different ways to provide zLeaf with the IP number of the machine running z-Tree:
  • If you place z-Tree and zLeaf in a common network directory, you should have no problem. z-Tree writes it's IP number into the file "server.eec" in its home directory or into the zleafdir (see Configurable Directories). zLeaf checks whether there is this file in it's (zLeaf's) home directory. If the file is found, zLeaf tries to connect with z-Tree on the machine with the IP number given in this file.
  • You can specify the IP number with the command line option "/server". The easiest way to do this is to create a shortcut to zLeaf.
  • If no other IP number is specified, zLeaf tries to connect with z-Tree on the local machine.
top of page

I wonder if you have any advice about how we should organise the file structure?


There are some tips in the "What's new in 2.0"-manual (5. Configurable Directories). Furthermore, the following picture shows our current installation.

On this picture:
"z-Tree experiments" is the shortcut:
z-Tree /datadir expdata /leafdir ..\zleaf /privdir priv /tempdir temp /gsfdir temp
"z-Tree test" is the shortcut:
z-Tree /dir testtrash /leafdir ..\zleaf

Permissions:
Experimenters have read and write permission in all directories.
Subjects have read permission in the zleaf directory.

Startup procedure
We put a batch file (which lies on the server) into the startup folder of the subjects. This batch file should look about as follows (suppose "L:" is the volume of z-Tree and zleaf and you want to start the zLeaves in English):
-------------
L:
cd \zleaf
start zleaf /language english
-------------

top of page

I want to teach z-Tree in our lab. What is the best way to install it?


A: Install z-Tree and zLeaf in a directory on the local harddisk of each lab computer. Make shortcuts to zLeaf as explained in "How can I create different z-Leaves to test a treatment with several clients on a single computer ?".

top of page

How can I create different z-Leaves to test a treatment with several clients on a single computer ?


A: You create a shortcuts for each zLeaf you want to start. You have to conduct the following steps:
1. Click at the z-Left icon in the explorer.
2. In the "File" menu select "Create Shotcut".
3. In the "File" menu select "Rename" and give the shortcut a good name. You can for instance number the leafs: zleaf1, zleaf2,...
4. In the "File" menu select "Properties". A dialog opens.
5. In this dialog first click at the tab "Shortcut".
6. You have to enter the name into the command line which you find in the field "Target". So, if your zLeaf is located in the directory L:\zleaf, in this field you will find the text
L:\zleaf\zleaf.exe
If you want to use the name leaf2 you enter into the field target the line
L:\zleaf\zleaf.exe /name leaf2
Note: The option "name" is preceeded by a slash. You may use any combination of letters and numbers as name (in the example leaf2. However, spaces are not allowed.
PS: You can also use other command line options as "size" which determines the size of the zLeaf.

top of page

Testing with overlapping z-Leaves

If you want to test a program with more than one client on one computer, it is sometimes difficult to find out which zLeaf belongs to which client.  A good idea is to start the clients with slightly different sizes.  This works particularly well if you can run a test on a screen that is larger than the screens of the clients.  You can, for instance, start three z-Leaves in the following way:
zleaf /name normal /size 640x480
zleaf /name wide   /size 650x470
zleaf /name high   /size 630x490
In this way the z-Leaves are arranged as in the figure below and you can fetch each of the windows with the mouse.
top of page

Reduce Time-out Times after the Experiment has Started

One defines the time-out in the parameters for each stage.  Thisformulacan no longer be changed in the experiment.  Therefore, you defineTimeout = Timeout0;.  The variable Timeout0 can be changed in the period parameters.  It is also possible to do this during the experiment for the periods not yet started.
top of page

How to generate individual receipts

Instead of just printing the payment file you can use it to produce individual receipts with the mail merge function of your word processor.
In the following, we explain the procedure step by step (for MS Word).
Before the Session starts
  • Make a Mail Merge document. You can use the fields "Subject", "Computer", "Interested" "Name" and "Profit" and the variable you added to the payment file.
  • You can open the word processor and open the mail merge document.
When the payment file is written.
  • Open the mail merge document (or bring it to the front).
  • Open Mail Merge (Seriendruck) in the menu Extras.
  • Select in point 2 of the mail Merge manager the option "Open Data Source" and select the payment file. You find it in the directory where you started z-Tree or in the directory you defined with the privdir option. The easiest way to find it is to view the directory in details mode and sort it according to "Modified".
  • Select point 3 to generate the merged document.
  • Check whether the document is plausible and print it.
top of page

Observer Subject

You can define a subject who sees the results of the experiment.  For this you define a variable Observer which you set to 0.  In all stages we add in a program in the subjects table the line
Participate = if( Observer==0,1,0);
Next we define an additional stage in which the variables that are of interest here are shown on the active as well as on the waiting screen.  In the program using table functions, you have to omit the observer, i.e., youwrite lines such as the following:
AvOffer = average(Observer ==0, Offer);
Now we define a subject with
Observer =1;
With this an interested party may follow these variables at a PC different from the experimenter PC.
top of page

Checking of Exercises

You can leave the checking of exercises to the computer.  To this end you define a treatment that only contains the exercises.  Checkers check whether the values are correct.  Common errors can be caught by specialized checkers.  These must stand at the beginning.
Example:
 Add 3 and -4
 Checker: result != 7 / Note that the numbers are not both positive.
 Checker: result == -1 / There is an error in your calculation.
The check questions for the first treatment are attached to the welcome treatment so that the subjects need not wait until all have clicked . continue. on the welcome screen to begin answering the check questions.
top of page

Dutch Auction

In the Dutch auction a price clock that gradually runs backwards is shown.  As soon as a buyer says stop, he or she receives the goods at the price displayed at that moment.
In version 2.0 of z-Tree, you can program auctioneers: see in the appendix to the manual 3. The Dutch auction and postponed program execution
top of page

Last modified: January 28, 2010 (ztreeadm@iew.unizh.ch)