*! version 8.0 15Oct2023

help for ztree2stataAuthor: Kan Takeuchi (Ver. Oct 15, 2023)

ztree2stata -- Import data created by z-Tree

Syntax

ztree2stata
table
using
filename
[, options]

Main
clear replace data in memory

save save the data in memory

replace overwrite existing dataset

treatment(numlist) specify treatments to import

except(strings) specify strings that will be used to skip the automated renaming

Description

ztree2stata imports a z-Tree (Fischbacher, 2007) data file and converts it into Stata format.
Specifically ztree2stata opens an ASCII text file saved by z-Tree, keeps the data of the specified table,
renames variables using the variable names in z-Tree, and
converts the data into numerical type if possible.

Options

Main

clear permits the data to be loaded even if there is a dataset already in
memory and even if that dataset has changed since the data were last saved.

save allows Stata to save the data in memory as filename-table.dta.

replace permits save to overwrite an existing dataset.

treatment(numlist) specifies treatments that will be imported into memory.
If this option is omitted, then all treatments will be imported.

except(strings) specifies strings that will be used to skip the automated renaming.
If there is any trouble with variable names, then the except option may solve it. See the example below for more details.

Remarks

z-Tree records the various data during the experiment in multiple tabular formats, and after the experiment is completed,
these tables are combined and output as a single tab-delimited ASCII file with xls extension.
Several issues arise when Stata imports the file, including: (1) The file includes several tables (e.g., subjects, globals, and clients) that must be separated for analysis; (2) Because the file includes variable names as strings, all numeric data is also interpreted as strings; and (3) When z-Tree data includes several treatments, the width of the selected table varies with treatments, resulting in variables being recorded in different columns. ztree2stata can handle these issues and conveniently convert the z-Tree data file into Stata?fs dta format.

Quick Start

Import the subjects table of 040517_1230.xls

. ztree2stata subjects using 040517_1230.xls

Import the globals table of 040517_1230.xls after clear the data in the memory

. ztree2stata globals using 040517_1230.xls, clear

Import the data of from the 2nd and the 4th treatments and save the data in dta format

. ztree2stata subjects using 040517_1230.xls, treatment(2 4) save

Import the subjects table of 040517_1230.xls and 221211_1749.xls and combine them

. ztree2stata subjects using 040517_1230.xls, save

. ztree2stata subjects using 221213_1749.xls, clear save

. use 040517_1230-subjects, clear

. append using 221213_1749-subjects

Examples

. ztree2stata subjects using 040517XY.xls

Stata reads 040517XY.xls and keeps the data of the subjects table.

table = subjects; Specify one of the tables which have been defined in z-Tree.

filename = 040517XY.xls; Stata looks for 040517XY.xls in the current directory. It must be in the current directory.

. ztree2stata globals using 040517XY.xls, tr(2 4) save

Stata opens 040517XY.xls, keeps the data of the globals table in treatment 2 and 4, and save the data.

options = tr(2 4); Stata reads the data of treatment 2 and 4. If the data does not include some of the specified treatments, then it returns an error.

options = save; This option allows Stata to save the data in memory as 040517XY-globals.dta. To overwrite the existing file, use save with replace option.

. ztree2stata subjects using 050301AB.xls, except(foo goo)

options = except(foo goo); Some issues, particularly those related to variable names, can be resolved using the 'except' option. In this example, ztree2stata adjusts variables containing 'foo' and/or 'goo' to foo# or goo#, where # signifies their original column position. For example, variables 'food,' 'good?' and 'goodfood!' in columns 6, 7, and 10 are renamed as 'foo6', 'goo7', and 'goo10', respectively. When a variable name includes both 'foo' and 'goo', the latter in the 'except' option determines the new name, turning 'goodfood' into 'goo10'.

Technical Notes

ztree2stata cannot open Excel files. A data file created by z-Tree is not an Excel file but a tab-delimited
ASCII file, while its extension is xls. Therefore, once a data file is overwritten as an Excel file,
ztree2stata can no longer open it.

The following symbols will be deleted from the variable names:
exclamation marks (!), colons (:), semi-colons (;), equal signs (=), double quotation marks ("), and spaces ( ).
If this leads to issues or errors due to duplicate variable names, use the except option.

The except option can be used to eliminate any other symbols or letters from variable names.

Note that when there is an unpaired double quotation mark in a dataset, Stata's import results may not be as intended.

options = string is no longer required in the current version.

This command is provided as it is, without any warranty.

Python users can utilize ztree2python (Takeuchi, 2022), to read z-Tree data files in Pandas format.

References

Fischbacher, U. 2007.
z-Tree: Zurich Toolbox for Ready-made Economic Experiments. Experimental Economics 10: 171-178.

Takeuchi, K. 2022.
ztree2python.py, http://github.com/takekan/ztree2python.

Takeuchi, K. 2023.
ztree2stata: A data converter for z-Tree and Stata users. Journal of the Economic Science Association 9: 136-146.