For replication code and some Stata tools see my Github page: https://github.com/johannes-schmieder
Resources for Stata
This is a collection of some tools for Stata that I developed during my work. Most tools don't have helpfiles, but there are comments in the ado files that should give you an idea for how to use them. Any comments or suggestions for improvement are very welcome. Files can be downloaded at bottom of page.
stataex.zip
This is a set of files containing example code to create Latex Tables using Stata. The file template.do creates several summary and regression tables that are exported in a nicely formatted latex file that can be opened using any latex editor. There are various ado files included in a subfolder called tools that are necessary to run this code.
stata.xml
This file is an improved syntax highlighting file for the KDE text editor Kate / Kwrite. In particular it fixes some code folding issues. Simply copy the file into the folder: .kde/share/apps/katepart/syntax/ under your home (e.g. /home/username/) directory.
template.do
Template for do files.
gsave.ado help file: gsave.hlp
This tool allows to directly save Stata .dta files and compress them to the zip format if the tool gzip/gunzip is installed on the system (and the excecutable is in the search path). The resulting files will have the extension .dta.gz The Syntax is the same as for the standard Stata "save" command.
e.g. gsave MyData.dta
or gsave "My Data.dta" , replace
or gsave MyData, nolabel
This program is intended to be used in conjunction with "guse". The syntax of guse and gsave should be exactly the same as use and save and thus existing programs can be adjusted with minimal effort.
guse.ado help file: guse.hlp
This tool allows to directly read compressed Stata .dta files in the gzip format (and ending in .dta.gz) if the tool gzip/gunzip is installed on the system. The Syntax is the same as for the standard Stata "use" command.
e.g. guse MyData.dta if year==1999, clear
or guse Var1 Var2 in 1/100 using MyData.dta, clear
This program is intended to be used in conjunction with "gsave", which automatically compresses saved .dta files. The syntax of guse and gsave should be exactly the same as use and save and thus existing programs can be adjusted with minimal effort.
xtregfast.ado
This program allows to run standard fixed effects regressions just like xtreg with the fe option. The difference is that it is significantly faster, in my experience for large datasets it is about 15 to 20 times faster than Stata's build in xtreg command (this depends on the number of right hand side variables and observations). Currently xtregfast only allows for the basic standard errors, not for robust or clustered SEs. So it should be mainly used in the specification search part of an analysis. For large datasets (millions of observations), I found this very useful. The speed gains are entirely due to reimplementing xtreg in Mata. Stata Corp. should really update their current xtreg command.
mat2tex.ado
A tool to create a table from a matrix and convert it to Latex. Inspired by and partly based on mat2txt by Michael Blasnik & Ben Jann. A useful feature is that only 3 significant decimals are exported (unless otherwise specified), similar to the output of estout or outreg2. The code for this is based on a piece of code in outreg2 by Roy Wada.
Example (export results from tabstat in pretty latex table):
labellist varlist , l(labels) // Obtain the variable labels for all vars in varlist (see tool below)
tabstat varlist, by(year) statistics(mean) save
tabstatmat m // save results of tabstat in matrix m
matrix m = m' // transpose matrix
mat2tex using filename, m(m) bookt row("`labels'") title("Variable Means")
Exports matrix to file filename, using booktabs latex package, applying row labels and a title. Many other formatting options available: notes, landscape, append, placement, columnames, ...
mat2csv.ado
A tool to create a table from a matrix and convert it to a comma separated value (CSV) file. Based on the program mat2txt by Michael Blasnik & Ben Jann.
time.ado
Quick way to use the timer commands of stata.
Example
time command1
time command2
timer list
Would measure the time it takes executes the two commands and then lists the time.
forX.ado
A tool to run quick, one line for loops. Really just a way to streamline do files.
Syntax:
forX arglist : command
The command after the colon contains one or more "X". It is executed for each element of arglist, where X is replaced by the respective argument of the list. Example:
forX hello world : disp "X"
results in excecuting two commands: disp "hello" and disp "world"
writeln.ado
A tool to write a line to a text file.
Example:
writeln filename.txt "Hello World"
Writes the new line "Hello World" to the file filename.txt. If filename.txt does not exist it is created.
sumbygroup.ado
Creates a summary table of variable means for two or more groups of observations and allows to test for equality of means. The table is then displayed and exported as CSV file.
Usage:
sumbygroup varlist using filename.csv, conditions("x=1" "x=0")
Creates a table of means for the varlist separately by all observations for which x=1 and for all observations for which x=0. P-values for the difference in means are displayd. The table is then exported to filename.csv. You can also set column names, row names, a title and numeric format through various options.
labellist.ado
Usage:
labellist varlist
Creates a local macro containing all the variable labels of varlist. This can be very useful for setting row or columnlabels in matrices, for example in soe of the commands above, such as mat2tex or sumbygroup.
Bash Scripts for PDF handling
cps2pdf
Usage: cps2pdf output.pdf input1.ps input2.ps ...
Converts input postscript files to PDF files and combines them to output.pdf file.
txt2pdf
Usage: txt2pdf input.txt output.pdf
Converts text file to pdf file. Options for fontsize, landscape/portrait available.