Tables in Stata

Author

Russell Dimond

Published

October 21, 2022

Tables in Stata

Reproducibility is one of the key components of good research, and in practice that mostly means automation. However, one of the hardest tasks to automate is actually putting your research results in your paper. Stata 17 took a major step forward in this area by introducing new collect and table commands for collecting results and putting them in tables. They take some effort to use, but can create publication-quality tables in a reproducible way.

Alternatives

There are several alternatives in this space, listed from least to most flexible and most to least easy to use:

The outreg family of commands can produce nice regression tables fairly easily. The estout and esttab commands can do the same and add some tables of summary statistics. If you know these commands and they can make the table you want (without too much tweaking) you may want to continue using them. However, neither of them can go beyond the types of tables they were written for. The collect and table commands are much more flexible.

The dyndoc command allows you to write documents in Markdown containing automatically-generated Stata results. Markdown is great for some forms of communication but not for formal papers (yet). This web book was written in Markdown, though using JupyterLab and Quarto rather than dyndoc in Stata.

The putdocx command allows you to put just about anything you want in a Word document, but you have to specify every detail. If your goal is to make a table, collect and/or table will be much easier. On the other hand, collect export actually uses putdocx commands when it exports your table to Word, and it’s possible to have it generate that code so you can tweak it.

In practice you can also tweak your table after exporting it to Word, LaTeX, HTML, etc. Don’t spend unlimited time trying to get Stata code to produce the perfect table if you’ll only use that code once. On the other hand, manual tweaking goes against reproducibility.

What You’ll Learn From This Book

We’ll start with the table command, because it’s very useful all by itself and also serves as a gentle introduction to some of the concepts used by collect.

We’ll then move to the collect command and the collection framework more generally. The collection framework describes tables in abstract much like the grammar of graphics that underlies R’s ggplot describes data visualizations in abstract. We’ve found that researchers who try to work with tables without spending some time understanding the collections framework end up frustrated.

Finally we’ll talk about the many ways you can control the appearance of your table. (A likely future chapter: collecting all those appearance items into styles you can reuse in future tables.)