Exporting tabs and cross-tabs to MS Word from Stata with asdoc

  • 10

Exporting tabs and cross-tabs to MS Word from Stata with asdoc

Category:Blog Tags : 

For installation and other uses of asdoc, please see this short blog post.

Tabulation and Cross-tabs with asdoc

Exporting tables created by Stata commands such as tab, tabulate1, tabulate12, table, tabsum, tab1, tab2, and others to MS word is super easy with asdoc.  As with other commands, we need to just add asdoc as a prefix to the tabulation commands that includes tabulate, tabulate1 tabulate2, tab1, tab2, etc. Since frequency tables in Stata can assume different structures, asdoc writes these tables from log files.


One-way table

Example: One-way table

sysuse auto, clear 
asdoc tabulate rep78, replace


Please note that replace is asdoc option to replace the existing file. If we were to write to the existing file, we would then use option append, instead of replace.


Two-way table of frequencies


webuse citytemp2, clear

asdoc tabulate region agecat, replace


Example: Include row percentages


asdoc tabulate region agecat , nokey row replace

Note nokey suppresses the display of a key above two-way tables.


Example: Include column percentages

asdoc tabulate region agecat , nokey column replace

Example: Include row percentages, suppress frequency counts

asdoc tabulate region agecat, nokey row nofreq replace


One- and two-way tables of summary statistics

Example: One-way tabulation with summary statistics


sysuse auto, clear
asdoc tabulate rep78, summarize(mpg) replace


Example: Two variables tabulation with summary statistics

generate wgtcat = autocode(weight, 4, 1760, 4840)

asdoc tabulate wgtcat foreign, summarize(mpg) replace


Example: Suppress frequencies

asdoc tabulate wgtcat foreign, summarize(mpg) nofreq replace


Multiple-way tabulation (tab1)

tab1 produces a one-way tabulation for each variable specified in varlist.

Example: Multiple-way tabulation

sysuse nlsw88, clear
asdoc tab1 race married grade, replace


Two-way for all possible combinations (tab2)

Example: Two variables tabulation with summary statistics

asdoc tab2 race south, replace


Federico Podesta

December 5, 2018at 7:54 pm

Dear Attaullah,
I have just downloaded your asdoc program. It is wonderful. MANY MANY THANKS FOR YOUR EFFORT!!
Nevertheless, I have found a problem in Including row percentages in the two-way table of frequencies. If I run the code included in the asdoc help (Example 41), I will not get row percentages

webuse citytemp2, clear
asdoc tabulate region agecat , nokey row replace

Otherwise, I get row percentages if I simply run

tabulate region agecat , row

I’m wrong or there is a problem in your program? Thanks a lot in advance for any of your help!

Anne Marie Schak Jensen

December 7, 2018at 5:47 pm

Dear Mr Attaullah Shah
Thanks for the program asdoc in Stata it seems to work fine.


I face a similar issue as reported by Febrico. I don’t get row percentages, see Example 41 in the asdoc help file.

    Attaullah Shah

    December 7, 2018at 5:50 pm

    Fedrico and Anne Marie:

    You are right. This problem occurs due to a conflict of options of asdoc and tabulation. Option row is an option of asdoc, as well as the tabulate command, but asdoc has a preference and hence the option row is not passed to the tabulate command. As a solution, I have added option subopt() which will pass all such conflicting options to the relevant Stata commands. You can install this new beta version from my website first and then use this option.

    * To completely uninstall the previous version
    net install uninstall_asdoc, from(http://fintechprofessor.com) replace
    * Now install the new version
    net install asdoc, from(http://fintechprofessor.com) replace
     * Now use option subopt() option as shown below
    webuse citytemp2, clear
    asdoc tabulate region agecat , nokey subopt(row) replace

    I would appreciate if you can comment on asdoc youtube video.

    Please do cite asdoc in your research.

    In-text citation

    Tables were created using asdoc, a Stata program written by Shah (2018).


    Shah, A. (2018). ASDOC: Stata module to create high-quality tables in MS Word from Stata output. Statistical Software Components S458466, Boston College Department of Economics.

Anne Marie Schak Jensen

December 12, 2018at 7:24 pm

I have installed the beta version and now the row option works fine.

Richard Makurumidze

April 7, 2019at 3:18 am


Thank for this wonderful STATA module. I have 2 issues;

1. Trying to use it with tabulate command and giving the following error message “option matrow() not allowed”

2. Its seems not to work with the graph command i.e. it can export graphs to Word

Many thanks

    Attaullah Shah

    April 7, 2019at 11:06 am

    Richard Makurumidze: I have replied to your question in this blog post.
    For your second query, yes asdoc is not able to send graphs to MS Word. However, I am trying to add this functionality in the next premium version of asdoc, which I would asdocx. For more updates, keep visiting this page.


April 16, 2019at 9:17 pm

Dear Attaullah, Many thanks for asdoc,

I have a question that if I want to do a 2*2 table with chi-square, how can I have the P value in the export doc. I tried different ways just can not have p-value exported

    Attaullah Shah

    April 16, 2019at 9:41 pm

    Currently asdoc does not report additional statistics with tabulation commands. However, there is a workaround this issue. If you read the asdoc help file, you shall in Section # that there is a text() option which can be used for reporting text or any additional statistics from the r() and e() macros. Since tabulation command leaves the Chi2 and its P-value in r() macros, therefore, they can be written to the existing document using the text option. See the following examples

    webuse citytemp2
    asdoc tabulate region agecat, chi2 replace
    asdoc, text(Chi2 = `r(chi2)'  Pr = `r(p)')

Jiaqiong (Susan) Xu, PhD

May 16, 2019at 9:32 pm

Thank you so much for providing asdoc. It is very useful!

But I have a question. I just used your data and an example (example 44 in the help asdoc) to run the following,

sysuse auto, clear

asdoc tabulate rep78, summarize(mpg) replace

and got the error message:

option summarize() not allowed


Do you know what’s wrong with it?

Thank you!



Associate Research Professor of Biostatistics

Center for Outcomes Research

Houston Methodist DeBakey Heart & Vascular Center

Houston Methodist Research Institute

    Attaullah Shah

    May 16, 2019at 9:36 pm

    Dear Susan
    You are right, when I revamped asdoc to report better quality tabulation results, the task was so exhausting that I decided to skip the summarize option with tabulate. If I find enough motivation in the future, I shall work on that.

Leave a Reply

four × five =