Using the bysort prefix with tab commands in asdoc | Stata
Recently, Scott Siegal asked for the possibility of adding the bysort prefix with tabulate, tab, tab1, and tab2 commands to asdoc. Honoring his request, I have added the bysort support to asdoc.
The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.
net install asdoc, from(http://fintechprofessor.com) replace
Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.
Once installed, we can use asdoc by adding the word asdoc to any Stata Command. Let us start with the basic tabulation commands
asdoc with the tab command
The tab command of Stata is used to create a table of frequencies. When adding one variable with tab command, it creates a one-way tabulation. To export the results to MS Word, just add asdoc to the beginning of the command. Let us use the nslw88.dta dataset from the Stata installation.
sysuse nlsw88, clear
*Tabule the race variable
asdoc tab race
The above code generates the following table.
Tab with bysort variable
The bysort prefix can be used to repeat the one-way tabulation across groups of another variable. So if you care about repeating the tabulation of race variable across the categories of the married variable, we shall write the code as:
bys married: asdoc tab race , replace
Two-way frequency tables are created by adding two variables after the tab word. Let’s create a two-way table of race and smsa
Using bysort with two-way tables
The bysort prefix can be used to repeat the two-way tabulations across groups of another variable. So if we care about repeating the tabulation of race and smsa variables across the categories of the married variable, we shall write the code as: