Professional Documents
Culture Documents
Z-treeLecture Slides MUST READ
Z-treeLecture Slides MUST READ
Stefan Palan
stefan.palan@uni-graz.at
http://www.palan.biz/academic
References
2
Graz, SS 2012
Introduction
3
Graz, SS 2012
1. Introduction to z-Tree
4. Bathroom break
4
Graz, SS 2012
1. Introduction to z-Tree
5
Graz, SS 2012
1. Introduction to z-Tree
6
Graz, SS 2012
1. Introduction to z-Tree
General rules
Backup everything
7
Graz, SS 2012
1. Introduction to z-Tree
Client-server architecture
8
Graz, SS 2012
1. Introduction to z-Tree
Network topology
Source: Tutorial, p. 6.
9
Graz, SS 2012
1. Introduction to z-Tree
10
Graz, SS 2012
1. Introduction to z-Tree
Client name
Command line parameter, e.g.: zleaf /name pc1
11
Graz, SS 2012
1. Introduction to z-Tree
zleaf.exe
Language: /language
e.g. /language en, or /language english
Screen resolution: /size
e.g. /size 1024x768
ztree.exe
Change default directories
12
Graz, SS 2012
1. Introduction to z-Tree
zleaf.exe
name.ztt
name.ztq
name.txt
@1.ztt, @2.ztt,
@1.ztq, @2.ztq,
090330_0804.gsf
090330_0804.pay
090330_0804.sbj
090330_0804.xls
13
Graz, SS 2012
1. Introduction to z-Tree
Groups of n = 4 subjects
Contribution of subject i: ci 0, wi
1 4
Profit of subject i: i wi ci 1.6 c j
n j 1
New z-Tree treatment:
14
Graz, SS 2012
1. Introduction to z-Tree
Define parameters
15
Graz, SS 2012
1. Introduction to z-Tree
16
Graz, SS 2012
1. Introduction to z-Tree
17
Graz, SS 2012
1. Introduction to z-Tree
Add a button
Select the input item
Click TreatmentNew Button
Enter OK as name and click OK
18
Graz, SS 2012
1. Introduction to z-Tree
Profit calculation
19
Graz, SS 2012
1. Introduction to z-Tree
Profit display
Order of execution
Own contribution
20
Graz, SS 2012
1. Introduction to z-Tree
21
Graz, SS 2012
1. Introduction to z-Tree
22
Graz, SS 2012
1. Introduction to z-Tree
Test at will
23
Graz, SS 2012
1. Introduction to z-Tree
24
Graz, SS 2012
1. Introduction to z-Tree
Output in YYMMDD_hhmm.xls:
25
Graz, SS 2012
1. Introduction to z-Tree
26
Graz, SS 2012
1. Introduction to z-Tree
Payment file
Computer
Interested
Name
Player1
OK
Jane Parker
Player2
OK
Jim Smith
Player3
OK
John Doe
Player4
OK
Bill Farmer
C:\Institut\zTree\120328_1127.pay
Profit
21.52
15.43
20.00
17.23
74.18
Signature
27
Graz, SS 2012
28
Graz, SS 2012
2. Basics of z-Tree
Structure of a treatment
Background
Contains general settings
Defines the tables used in the treatment
Defines default Active Screen and Waiting Screen
Contains programs which run at the beginning of a period
Stages
Correspond to the screens displayed to subjects
Contain programs which run at the beginning of a stage
29
Graz, SS 2012
2. Basics of z-Tree
Creating a stage
Start
Timeout
Screen layout
Containers
Boxes
Absolute/relative size/position
Adjustment of the remaining box
30
Graz, SS 2012
2. Basics of z-Tree
Result:
31
Graz, SS 2012
2. Basics of z-Tree
Result:
32
Graz, SS 2012
2. Basics of z-Tree
Result:
33
Graz, SS 2012
2. Basics of z-Tree
Screen layout
34
Graz, SS 2012
2. Basics of z-Tree
Screen layout
1
4
35
Graz, SS 2012
2. Basics of z-Tree
36
Graz, SS 2012
37
Graz, SS 2012
Conditional output
Layout:
!text: 2="Less than the third.; 3="The
third.; 4="More than the third.;
Results:
Period 1+2:
Attention:
The first text version that is being
displayed sets the size of the item. If
the variable value (and accordingly
the text) changes, longer text may
not display correctly. Therefore, add
enough blank space after each
option to display even the longest.
Period 3:
Period 4+:
A Comprehensive Introduction to z-Tree
Stefan Palan, Karl-Franzens-University Graz
38
Graz, SS 2012
Result:
39
Graz, SS 2012
Formatted text
Layout:
!text: 1="{\rtf \fs22\b\i This item displays
formatted text.}"
Result:
40
Graz, SS 2012
Result:
41
Graz, SS 2012
Conditional formatting
Layout:
<> !text: 1="{\rtf \fs24 <\Period | !text:
1="\i " 2="\b ">Test}"
Result:
Period 1:
Period 2+:
42
Graz, SS 2012
Effect
tabulator
new paragraph
new line
thick dot
aligned to left
aligned to right
centered
bold
not bold
italic
not italic
small and inferior numbers (index)
small and superior numbers (exponent)
crossed through
underline
do not underline
Text color. n is the index of the color table which is defined by colortbl. See example.
Font size in units of half a dot. The font size must be explicitly given, otherwise it is larger
(24) than usual in z-Leaf.
43
Graz, SS 2012
Alternative formats
44
Graz, SS 2012
4 Programming: Basics
Variable refresh
Put text in layout (as opposed to label) section to
allow variables to refresh
Screen space is reserved for initial value of variables
45
Graz, SS 2012
Select a button
Click Treatment-New Checker
46
Graz, SS 2012
Programming basics
47
Graz, SS 2012
4 Programming: Basics
48
Graz, SS 2012
4 Programming: Basics
Variable types
String variables
Do not exist
(There is a limited possible workaround)
49
Graz, SS 2012
4 Programming: Basics
50
Graz, SS 2012
4 Programming: Basics
Participate variable
Variable in the subjects table
Set to 0 to make a subject skip this stage (must be
done in the stage background)
LeaveStage variable
Variable in the subjects table
Set to 1 to make a subject move immediately to the
waiting screen of the current stage
51
Graz, SS 2012
4 Programming: Basics
52
Graz, SS 2012
4 Programming: Basics
53
Graz, SS 2012
4 Programming: Basics
54
Graz, SS 2012
4 Programming: Basics
55
Graz, SS 2012
4 Programming: Basics
# practice periods
# paying periods
Exchange rate
Show up fee
56
Graz, SS 2012
4 Programming: Basics
57
Graz, SS 2012
4 Programming: Basics
TotalProfit
Table: session
FinalProfit
MoneyAdded
MoneyToPay
58
Graz, SS 2012
4 Programming: Basics
59
Graz, SS 2012
4 Programming: Basics
Programs run in a
table
Programs can contain
commands running in
different table
Structure here is:
globals
subjects
contracts
Scope operators:
: one step up
\ all steps up to
globals table
60
Graz, SS 2012
4 Programming: Basics
Table functions
Examples:
sum ( [condition] , variable );
average ( [condition] , variable );
product ( [condition] , variable );
minimum / median / maximum ( [condition] , variable );
find ( [condition] , variable );
count ( [condition] );
regressionslope ( [condition] , x , y );
stddev ( [condition] , variable );
61
Graz, SS 2012
4 Programming: Basics
Variables in
table globals
Command run in
table subjects
Variable in
table subjects
62
Graz, SS 2012
4 Programming: Basics
Table B
Table C
63
Graz, SS 2012
4 Programming: Basics
64
Graz, SS 2012
4 Programming: Basics
Loops in z-Tree
65
Graz, SS 2012
Box types
66
Graz, SS 2012
5. Box types
Box types
Container box:
Used to organize other boxes on the screen
67
Graz, SS 2012
5. Box types
Box types
Contract list box:
Used to display records from a z-Tree table:
Condition for
displaying box
Makes own
records font
color blue
Condition for
displaying
individual
records
Variables to
sort by
68
Graz, SS 2012
5. Box types
Box types
Contract list box:
Code:
Output:
69
Graz, SS 2012
5. Box types
Box types
Contract list box:
Contracts can be selected
Button in contract list box:
Program is executed for selected contract
Error message if no contract selected
Current subjects contract in subjects table
can be accessed using scope operator, e.g.
Creator = :Subject;
70
Graz, SS 2012
5. Box types
Box types
Contract creation box:
Used to create new records in a z-Tree table:
Condition for
displaying box
Table wherein new
records should be
created
Additional settings for
contract creation
Number of contracts
which can be entered
simultaneously
71
Graz, SS 2012
5. Box types
Box types
Contract creation box:
Code:
Output:
72
Graz, SS 2012
5. Box types
Box types
Contract creation box:
Item entry limitations determine what values are
permissible
Program in button
Used to write additional variables
Automatically limits its operation to new record
73
Graz, SS 2012
5. Box types
Box types
Grid box:
Used to display records from a z-Tree table:
Condition for
displaying box
Defines size of
the box
Determines
how the
ordering of the
items is
interpreted
Formatting
options
74
Graz, SS 2012
5. Box types
Box types
Grid box:
Code:
Output:
Attention:
Drawing a grid box with
many items takes z-Tree
a long time. Whenever
possible, use e.g. a
contract list box instead.
75
Graz, SS 2012
5. Box types
76
Graz, SS 2012
5. Box types
Box types
Chat box:
Used to display/exchange chat messages:
Condition for
displaying box
Variable name
and entry
limitations
Condition for
displaying
individual
records
Output text
format
77
Graz, SS 2012
5. Box types
Box types
Chat box:
Code:
Output:
78
Graz, SS 2012
Programming
79
Graz, SS 2012
Running programs
Program in a stage
Runs at beginning of stage, before checking Participate
Program in a button
Program in subjects table runs only for the subject
pressing the button
Runs after checkers
80
Graz, SS 2012
Parameter table
1. Specific parameters
(after programs in the background)
2. Role parameters
81
Graz, SS 2012
Tab-separated values
A Comprehensive Introduction to z-Tree
Stefan Palan, Karl-Franzens-University Graz
82
Graz, SS 2012
Period structure
1. Setting of standard variables
83
Graz, SS 2012
84
Graz, SS 2012
Table dumper:
parameters
parameters
parameters
parameters
Period
1
1
1
x
68
3
94
85
Graz, SS 2012
86
Graz, SS 2012
87
Graz, SS 2012
Groups
88
Graz, SS 2012
Group matching
Absolute stranger:
89
Graz, SS 2012
90
Graz, SS 2012
Strategy:
Put data into a table
Calculate the rank
Transfer the data
back
91
Graz, SS 2012
92
Graz, SS 2012
Adding records
Contract creation boxes
Command: contracts.new { x=1; }
Changing records
In contract list boxes and contract grid boxes
Command: contracts.do { x=2; }
Deleting records
Marking a contract as deleted (e.g. status = 3;)
* Adapted from lecture slides by Verena Utikal, Friedrich-Alexander-University Erlangen-Nrnberg.
93
Graz, SS 2012
As if in contracts.new/do {}
94
Graz, SS 2012
95
Graz, SS 2012
Example record
ID = 1;
price = 23;
volume = 5;
status = 0;
type = 0;
Variable status
0 open offer
1 traded
2 cancelled
3 invalidated
4 expired
buyer = 1;
seller = 0;
offertime = 2.381;
statustime = 18.221;
96
Graz, SS 2012
Variable type
1 buy offer
1 sell offer
97
Graz, SS 2012
Example records:
ID
price
volume
status
type
buyer
seller
offertime
statustime
23
-1
5.304
-77777
25
7.221
18.475
30
13
12.100
16.224
15
-1
25.132
33.251
98
Graz, SS 2012
Variable intialization:
Initialize variables
99
Graz, SS 2012
Order input
100
Graz, SS 2012
Order input
101
Graz, SS 2012
Order output
102
Graz, SS 2012
Order output
//Processes trade
//Updates contract information
seller = :Subject;
status = 1;
statustime = gettime() - \Starttime;
//Updates cash and share holdings
subjects.do {
//Updates seller
if ( Subject == :seller ) {
NumTrades = NumTrades + 1;
Cash = Cash + :price;
Shares = Shares - :volume;
}
//Updates buyer
if ( Subject == :buyer ) {
NumTrades = NumTrades + 1;
Cash = Cash - :price;
Shares = Shares + :volume;
}
}
103
Graz, SS 2012
Order output
104
Graz, SS 2012
Order output
105
Graz, SS 2012
Order output
Buy orders
Sell orders
106
Graz, SS 2012
11. Exercises
107
Graz, SS 2012
11. Exercises
108
Graz, SS 2012
11. Exercises
No information is lost:
Who made the first offer, who accepted
Time where the offer and acceptance were made
Initial volume, how much was exchanged per transaction
109
Graz, SS 2012
Table transactions
offerID (ID)
acceptanceID (ID)
accepterID
volume
time
(price)
110
Graz, SS 2012
111
Graz, SS 2012
Questionnaires
112
Graz, SS 2012
7. Questionnaires
Questionnaires: Overview
Solicitation of feedback
Display of results
113
Graz, SS 2012
7. Questionnaires
Questionnaires: Overview
114
Graz, SS 2012
7. Questionnaires
115
Graz, SS 2012
7. Questionnaires
116
Graz, SS 2012
7. Questionnaires
Questionnaires
Automatic checking of control questions
117
Graz, SS 2012
Helpful Advice
118
Graz, SS 2012
8. Helpful advice
Helpful advice
119
Graz, SS 2012
8. Helpful advice
Commenting
Comment your code extensively:
Single-line commenting:
// until the end of the line
Inline commenting:
x /* comment */ =5;
Multi-line
commenting:
/* multi
line
comment */
120
Graz, SS 2012
8. Helpful advice
Helpful advice
Test extensively
121
Graz, SS 2012
8. Helpful advice
Helpful advice*
122
Graz, SS 2012
8. Helpful advice
Table lifetime
Period (contracts, globals, subjects, )
Treatment (summary, )
Session (session, )
A Comprehensive Introduction to z-Tree
Stefan Palan, Karl-Franzens-University Graz
123
Graz, SS 2012
8. Helpful advice
Helpful advice
124
Graz, SS 2012
8. Helpful advice
Timelog
125
Graz, SS 2012
8. Helpful advice
Timelog
Create entries for all events of interest:
126
Graz, SS 2012
8. Helpful advice
Timelog
Create entries for all events of interest:
Period
ID
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
Time
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Subject
0
0.328
0.421
0.546
3.916
6.755
7.457
7.987
13.588
16.505
16.833
22.714
25.257
25.881
31.746
31.762
34.133
Event
0
0
0
0
1
1
1
1
1
2
2
2
3
3
3
0
0
1
2
4
6
7
8
7
9
18
7
9
18
7
9
18
19
20
127
Graz, SS 2012
8. Helpful advice
Reformatting possibilities:
Manually
Using z-Trees Tools - Separate tables command
(see following slides)
128
Graz, SS 2012
8. Helpful advice
129
Graz, SS 2012
in advice
Part III Advanced8.Topics
Helpful
z-Tree
130
Graz, SS 2012
8. Helpful advice
Time data
Recorded for all button clicks (if stage has a timeout)
Times are recorded as time remaining in period:
131
Graz, SS 2012
Troubleshooting
132
Graz, SS 2012
9. Troubleshooting
133
Graz, SS 2012
9. Troubleshooting
Debugging*
134
Graz, SS 2012
9. Troubleshooting
Crash handling
Client Crash
135
Graz, SS 2012
9. Troubleshooting
Crash handling
Client Crash
136
Graz, SS 2012
9. Troubleshooting
Crash handling
Server Crash
Restart z-Tree
137
Graz, SS 2012
9. Troubleshooting
Crash handling
Server Crash
138
Graz, SS 2012
9. Troubleshooting
Crash handling
Server Crash
Restart treatment
Run/Start
treatment
(<F5>)Erlangen-Nrnberg.
* Adapted fromwith
lecture slides
by Verena Utikal,
Friedrich-Alexander-University
139
Graz, SS 2012
Graphics Teaser
140
Graz, SS 2012
141
Graz, SS 2012
142
Graz, SS 2012
z-Tree Wiki:
https://www.uzh.ch/iew/ztree/ssl-dir/wiki/
A Comprehensive Introduction to z-Tree
Stefan Palan, Karl-Franzens-University Graz
143
Graz, SS 2012
Exercises
144
Graz, SS 2012
11. Exercises
Hints:
y=roundup(random()*10,1));
Profit=if(x==y,100,0);
* Adapted from lecture slides by Verena Utikal, Friedrich-Alexander-University Erlangen-Nrnberg.
145
Graz, SS 2012
11. Exercises
2 subjects, 1 period
146
Graz, SS 2012
11. Exercises
Structure
Subject B
Program start
147
Graz, SS 2012
11. Exercises
2 subjects, 1 period
148
Graz, SS 2012
11. Exercises
149
Graz, SS 2012
11. Exercises
distance=abs(x-0.5*subjects.average(same(Group),x));
Winner=if(distance==subjects.minimum(same(Group), /*
*/ distance),1,0);
Extra tasks:
150
Graz, SS 2012
11. Exercises
151
Graz, SS 2012
11. Exercises
If a subject buys the good for the current price, the auction
for the next good starts, until all goods are sold
152
Graz, SS 2012
Karl-Franzens-University Graz
Stefan Palan
stefan.palan@uni-graz.at
http://www.palan.biz/academic