Stata Table Gallery (sample tables with code; contributions welcome!)
A variety of packages (and manual techniques) are available for programmatically generating LaTeX output using Stata.
Generally, more automated approaches such as estout
/esttab
make it easy to quickly generate nearly-production-ready output, but make it more difficult (if not impossible) to implement significant customization. (That is, costs may be convex.) Automated approaches may also work best with interactive and exploratory analysis, since attractively formatted results can also be displayed as Stata output or exported as simple text or csv files.
Semi-automated approaches such as json-this
/coeftable
and stata-tex
generally require manually creating LaTeX code to generate even simple tables, but their output is fully customizable. (That is, costs may be concave.)
Semi-automated approaches often involve saving calculated values in an external file before generating LaTeX output. (This is also possible with automated approaches using Stata’s estimates save
command.) While slightly more complicated, this separation of analysis from table generation has real advantages. For example, saving calculated values
- Allows restructured tables to be generated without re-running estimation commands;
- Makes it easy to generate identically-structured tables with different samples, variable definitions, etc.;
- Allows easy generation of alternate table versions, such as for a paper vs. a presentation;
- Allows calculated values to be accessed by other scripts (e.g., for plotting);
- Works well with version control.
These packages generate tex files (and perhaps other formats) with customization via Stata command options.
- Install using
ssc install estout, replace
- Relative to the documentation on the package page, descriptions of some options are easier to find in the old documentation, including at the “Advanced” page
- Several examples with code at this site’s (minimal) gallery page
- Estimation can be separated from table creation by saving estimates (as
.ster
files) using Stata’sestimates save
command; this supercedes the olderestwrite
package - Examples from RePEc documentation page (older?)
- Creating Publication-Quality Tables in Stata from University of Wisconsin SSCC
- Regression Tables That Look Like Those in Journal Articles from UCLA IDRE
- Automated Table generation in Stata and integration into LaTeX (blog post; continued in parts 2 and 3) by Jörg Weber
- The Stata-to-LaTeX guide (blog post with detailed, documented examples including shared Overleaf files) by Asjad Naqvi
- Customization example using prehead and postfoot by Eyal Frank
- Stata Journal article by Ben Jann
- Install using
ssc install outreg2, replace
- Supercedes older
outreg
package - Using outreg2 to report regression output, descriptive statistics, frequencies and basic crosstabulations from Princeton DSS
For descriptive statistics and tabulations, not regression results
- Install using
ssc install tabout, replace
- Several examples with code at this site’s (minimal) gallery page
- Slides with examples by Ian Watson
For summary statistics and orthogonality tables, not regression results
- Install using
ssc install orth_out, replace
"A programmer's command to write formatted Word or TeX tables from a matrix of statistics," frmttable
is the command that underlies outreg
, but can also be used directly to generate more customized output
- Help file from RePEc
- Slides with background by John Luke Gallup
- Stata Journal article by John Luke Gallup
These packages typically fill in a manually created tex template with calculated values.
Calculated values are saved as json and then inserted into an external tex template
- Install manually from github pages (requires Python)
Calculated values are saved as csv and then inserted into an external tex template
- Install manually from github page (requires Python)
- Explanatory Twitter thread by Paul Novosad
Calculated values are saved as a set of tex macros
- Install using
ssc install texresults, replace
- Latest builds can be installed manually from github package page
- Discussion with examples by Alvaro Carril
Calculated values are saved as Stata datasets and then exported as tex
- Install using
ssc install regsave, replace
andssc install texsave, replace
- Latest (developer) builds can be installed manually from github package pages (regsave and texsave)
sortobs
package can help with ordering variables for tex output- Slides with examples by Julian Reif
Calculated values are inserted directly into a tex template included in the do file
- Install using
ssc install texdoc, replace
- Slides with examples by Ben Jann
- Example Twitter thread by Magdalena Bennett
Calculated values are saved as .ster
files, desired values are arranged as a Stata matrix, and then exported as tex
- Install manually from github page
- Explanatory Twitter thread by Alessandro Martinello
Tables are set up as a Stata dataset and then exported as tex
- Install using
ssc install listtab, replace
- Stata Journal article by Roger Newson
- Supercedes older
listtex
package parmest
package can produce Stata datasets of estimated parameters
These approaches are usually used to more fully integrate analysis into document creation, but can also be used to generate LaTeX output (perhaps requiring a tool like pandoc to convert from markdown or HTML to LaTeX).
- Stata’s built-in
dyntext
command (text, including tex source) ordyndoc
command (markdown) - The
markstat
package by Germán Rodríguez
- Generate tex code in string variables and export using
outsheet
(per Damon Jones’ Twitter thread) - Write tex code directly using
file write
(per Paul Goldsmith-Pinkham’s example) - Convert regression output from Stata log files to tex using
extract-from-stata
(package page) - Use r instead of Stata (perhaps with the
stargazer
package for LaTeX output)
I created this page in response to Twitter discussions suggesting there’s interest in learning more about the wide range of techniques researchers use to work with Stata and LaTeX. I also wanted to learn more about how to use github (where this page is hosted).
I added the resources I was aware of, and quickly characterized them as best I could. Please feel free to suggest additions or updates, either by submitting pull requests to the github respository (if you know how to do so), or by contacting me directly.