← See Stata 19's features
Highlights
New table options
Add title and style it
Add notes and style them
Export the table
Word
Excel
HTML
LaTeX
And more
anova and oneway now post their ANOVA table to a matrix
Improved support to collect the ANOVA results and build your own customizable table
New ability to hide factor-variable levels in table headers
New support for collections
One-way tabulations, including cumulative percentages
Two-way tabulations, including measures of association
One-way and two-way tables of summary statistics
Tabulations of survey data, including tests
More collect features
Query the layout specification
Remove specific results from your collection
See more reporting features
Building customizable and reproducible tables is now even easier in Stata 19. The table command for creating and customizing tables in a single command now allows you to add a title and notes and export tables. It is also easier to create tables from a collection. anova, oneway, and tabulate now work seamlessly with collect. And collect now allows you to query layout specifications and remove results from a collection.
-> More powerful single-command table generation
-> Customizable ANOVA tables
-> Collections with tabulate
-> Query the layout
-> Remove results from a collection
The table command is a flexible tool for creating a tabulation, table of summary statistics, table of regression results, or table of results from other Stata commands. Its options allow you to customize numeric and string formats, add stars, and more. Now you can add and customize a title and notes. You can also export the table directly to Excel, Word, LaTeX, and more. And you can do this all with a single table command.
Here we use data from the Second National Health and Nutrition Examination Survey (NHANES II) (McDowell et al. 1981). We tabulate the hlthstat variable, which contains individuals’ self-reported health status categories. We also specify options for adding a title and notes and for exporting the table to a Word document.
. webuse nhanes2l (Second National Health and Nutrition Examination Survey) . table hlthstat, statistic(frequency) statistic(percent) missing title(Table 1) note("Source: NHANES II") note("Sample includes blank but applicable and missing responses.") export(table.docx) Table 1
Frequency Percent | ||
Health status | ||
Excellent | 2,407 23.25 | |
Very good | 2,591 25.03 | |
Good | 2,938 28.38 | |
Fair | 1,670 16.13 | |
Poor | 729 7.04 | |
. | 2 0.02 | |
Blank but applicable | 14 0.14 | |
Total | 10,351 100.00 | |
We created a reproducible table and exported it to a Word document in one line of code.
anova and oneway now store their results in the r(ANOVA) matrix. In addition, there is now built-in support to collect these results, so you can build, customize, and publish ANOVA tables in your reports.
Consider the following one-way ANOVA that models the average weight of apples taken from trees treated with varied amounts of fertilizer. Below, we load the data, fit the model, collect the results, apply the new anova collection style, and replay the default layout of our customizable ANOVA table.
. webuse apple (Apple trees) . oneway weight treatment . collect get r(), command(oneway) . collect style use anova, replace . collect layout Collection: default Rows: term Columns: result[SS df MS F p] Tables: cmdset Table 1: 3 x 5
SS df MS F statistic Prob>F | ||
Between groups | 5295.54 3 1765.18 21.46 0.0013 | |
Within groups | 493.59 6 82.27 | |
Total | 5789.14 9 643.24 |
The new command() option of collect get provides command-specific result labels that are similar to those obtained when using the collect prefix.
The anova style can be applied to results collected from oneway or anova to automatically create an ANOVA table. We could use additional collect commands to further customize this table and export it.
The tabulate, tab1, tab2, tabi, and svy: tabulate commands are frequently used for creating tabulations and tables of summary statistics. Beyond simple tabulations, tabulate provides measures of association, and svy:tabulate provides various tests for survey data. You can now easily build tables that you can customize, style, and publish in reports from the results of these commands. Simply add the collect option to instruct Stata to create a new collection that you can customize with the collect suite of commands.
Below, we create a one-way table of frequencies for regions in our census data. We use the sort option to show the table in descending order of frequencies, and we use the collect option to put those frequencies into a collection named Tabulate.
. sysuse census (1980 Census data by state) . tabulate region, sort collect
Census | ||
region | Freq. Percent Cum. | |
South | 16 32.00 32.00 | |
West | 13 26.00 58.00 | |
N Cntrl | 12 24.00 82.00 | |
NE | 9 18.00 100.00 | |
Total | 50 100.00 |
We type collect to see that we now have the Tabulate collection in memory.
. collect Collections in memory Current: Tabulate
Name No. items |
Tabulate 14 |
default 34 |
collect layout shows us the default table layout for the collection that was created by our tabulate command.
. collect layout
Frequency Percent Cumulative |
Census region |
South 16 32.00 32.00 |
West 13 26.00 58.00 |
N Cntrl 12 24.00 82.00 |
NE 9 18.00 100.00 |
Total 50 100.00 |
If desired, we can further customize this table and then export it to the file type of our choice.
To see the layout specification and the table it creates, you can type
. collect layout
However, you may want to see the layout specification without seeing the table. You can now type
. collect query layout
With the collect prefix and the collect get command, you collect results from commands that post their results in r() and e(). You can even collect custom results you define using expressions.
Now you can remove results from your collection with collect unget.
McDowell, A., A. Engel, J. T. Massey, and K. Maurer. 1981. Plan and operation of the Second National Health and Nutrition Examination Survey, 1976–1980. Vital and Health Statistics 1: 1144.
Read more about the table command in [R] table oneway, [R] table twoway, [R] table multiway, [R] table regression, [R] table summary, [R] table hypothesis tests, and [R] table in the Stata Base Reference Manual.
Read more about tabulate in [R] tabulate oneway, [R] tabulate twoway, and [R] tabulate, summarize(). For information on tab1, see [R] tabulate oneway, and for information on tab2 and tabi, see [R] tabulate twoway.
For information on using tabulate with survey data, see [SVY] svy: tabulate oneway and [SVY] svy: tabulate twoway in the Stata Survey Data Reference Manual.
To read more about tabulate collection styles, see [TABLES] set tabulate_style and [TABLES] Predefined styles in the Stata Customizable Tables and Collected Results Reference Manual.
For information on anova and oneway, see [R] anova and [R] oneway. See [TABLES] Example 8 for an example using anova and collect, and the anova collection style is described in [TABLES] Predefined styles.
To read about collect query layout and collect unget, see [TABLES] collect query and [TABLES] collect unget, respectively.
Learn more about Stata's reporting features.
View all the new features in Stata 19.