Stata is now ready to help you create both standard and customized tables, whether you want a table for the web that looks like,
or a table for your paper in Word® that looks like,
or that same table for your LaTeX paper,
You can create a lot of different tables directly from the reimagined table command—from simple cross-tabulations all the way to comparative regression tables.
One-way frequencies and percentages
Two-way frequencies and percentages
Multiway frequencies and percentages
Multiway means, SEs, frequencies, and percentages
How can the updated table command do all that? It is built on top of a whole new system for collecting stored results from commands and displaying those results as tables. Stata 17 gives you access to that system too.
We admit that the collection system harbors some complexity. One feature that makes it more approachable is styles. You saw styles being used on the table commands for the tables presented above.
You can design your own styles for the types of tables you often create. Once you have designed a style, you simply apply that style to other collected results to create a table—a table with your preferred layout, formatting, and appearance. You can also use the styles shipped with Stata or styles created by your colleagues.
Let’s create a table using the collection system. We grab the NHANES II data (McDowell et al. 1981) that are used in many examples in the manuals.
. webuse nhanes2l
First, we collect the results for a simple regression of systolic blood pressure on weight in kilograms. To collect the results, all we do is place the collect prefix in front of the command:
. collect: regress bpsystol weight
Why stop with one regression? Let’s add indicators for birth sex and for levels of age group to our regression. We collect those results too:
. collect: regress bpsystol weight i.sex i.agegrp
Finally, let’s interact sex and age group, and collect those results:
. collect: regress bpsystol weight i.sex i.agegrp i.sex#i.agegrp
We will use a relatively simple regression style file that places the standard errors below the coefficients and adds a few model statistics to the bottom. The style’s name is myreg. With a style in hand, all we do is ask the system to use that style. collect will then lay out, format, and style the table according to the specified style. We can then preview the table.
What if you prefer confidence intervals? We also have a style that shows just coefficients and confidence intervals—style myregci. We simply tellcollect to use style myregci:
All we did to change from the first table to the second table was change the style. The two styles we applied to our collection produced distinctly different tables. The second style even puts the coefficient statistics side by side rather than above and below. Style myregci was derived from style myreg. To create myregci from myreg, we only had to type three lines:
. collect style autolevels result _r_b _r_ci , clear
. collect layout (colname) (cmdset#result)
. collect style column, dups(center)
The first line tells collect to report only coefficients (_r_b) and confidence intervals (_r_ci). The second line tells collect how the table is to be laid out. In words, put the covariate names (colname) on the rows of the table, and put each combination of estimation command and coefficient/confidence interval on the columns (cmdset#result). The third line tells collect to center the estimation-command labels—(1), (2), and (3)—over the two columns that each label spans.
Once your table is created, you can get it into your report quickly.
. collect export mytable.docx
and your table is in a file ready for Microsoft Word®.
. collect export mytable.html
and your table is ready for the web.
. collect export mytable.tex
and your table is ready to go into your LaTeX file.
You can even use the putdocx, putexcel, and putpdf systems to insert your tables directly into longer documents.
Once you have collected your results, you can work using commands to lay out, format, and style your table. Or, you can use the interactive Tables Builder.