Simple tables in the results window
This section introduces three commands to display tables in the results window. This is mainly useful for inspecting the data while the subsequent chapters focus on how to export results tables.
-
tabulate:
- Depict the (relative) frequencies of the values of one variable or of the combination of two variables
- To depict means, sd etc. use the option summarize
-
table:
- While tabulate is surely the simplest way to create tables, you can also use the command table, which is more flexible
- Allows you to modify design details such as alignment or cell width
- Provides a nice alternative to collapse, as you can replace your data with summary statistics using the option replace
- You can simply use the data editor to copy the table to Excel
-
tabstat:
- This is essentially a flexible version of the command summarize
- If you want something similar to table or tabulate, you need to specify the by-option
Simple tables using tab, tabstat, table
* Topic 1: tab, tabstat and table
sysuse census, clear
* tab (tabulate)
tab state
tab state region
tab state region, row // use options row or col for relative frequencies
tab region
tab region, summarize(pop) // Depicts means
tab region, nol
fre region // package allows display of values and value labels at the same time
*fre from http://fmwww.bc.edu/RePEc/bocode/f
* table
table region
table region, contents(freq mean pop)
table region, contents(freq mean pop) cellwidth(20) // modify design details
table region, contents(freq mean pop sd pop) replace // careful - replaces data with summary statistics, use data editor to copy to Excel
sysuse census, clear
* tabstat
tabstat pop // by default calculates overall mean of variable
tabstat pop, stat(count mean sd min max) // specify statistics in option stat
tabstat pop, by(region) // similar to table or tabulate
tabstat pop, stat(count mean sd min max) save // option saves statistics in r()