Export summary statistics to LaTeX

The ado-file --sutex-- (has to be installed by typing --findit sutex-- into the Stata command window) provides a simple way to export summary statistics from Stata to a separate LaTeX-file. It is limited in individualised adjustment, but quite OK for most applications. By default, you get mean and standard deviation for variables VAR1, VAR2, VAR3, etc. A syntax could be:

sutex VAR1 VAR2 VAR3, lab nobs key(descstat) replace ///
file(descstat.tex) title("Summary statistics") minmax

with the following options included:
lab (use labels instead of variable names)
nobs (add number of observations
key(STRING) (add a key to the table so that you can reference from the text by typing \ref{STRING} in the LaTeX file)
file(STRING) (generates a new .tex-file)
title("STRING") (adds a title to the table)
minmax (adds minimum and maximum)
replace (replaces the old file when there was a new run)

The new .tex-file (here: descstat.tex) can be easily included into another .tex-file by using the LaTeX-command: \input{descstat}

Alternative (manual) way:

quietly: tabstat VARLIST, c(s) stat(mean) save
matrix output = r(StatTotal)'
quietly: tabstat `desc', c(s) stat(sd) save
matrix output = output,r(StatTotal)'

 

outtable using TEXFILENAME, mat(output) center replace ///
caption("TITLE") nobox f(%12.2fc) label ///
clabel(descstat)

NOTE: before using this alternative approach, you have to install the ado-file —outtable–. In the field --stat(mean)-- you can enter any statistic generated by stata (count, sd, min, max etc)

2 thoughts on “Export summary statistics to LaTeX

  1. Thank you for the outtable code! Its very helpful.

    An issue: For some reason, the columns are not appearing right aligned with this format f(%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc). I have removed center from the code. I see the default is to flush it left. Do you have any suggestions on what I can do?

    my code is:
    f(outtable using “$path/tables/test1”, mat(output) replace ///
    caption(“Summary Statistics – Round 72”) nobox f(%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc) label ///
    clabel(descstat)

    Many thanks,

    Pallavi

Leave a Reply