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

  • 17

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

17 Comments

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.
http://fintechprofessor.com/2018/06/18/exporting-tabs-and-cross-tabs-to-ms-word-from-stata-with-asdoc/

https://www.statalist.org/forums/forum/general-stata-discussion/general/1435798-asdoc-an-easy-way-of-creating-publication-quality-tables-from-stata-commands

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
    uninstall_asdoc
    
    * 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.
    https://www.youtube.com/watch?v=61ks3cMPz3c

    Please do cite asdoc in your research.

    In-text citation

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

    Bibliography

    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

Greetings,

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.

YZ

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

    YZ
    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 see in Section 1.9 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

r(198);

Do you know what’s wrong with it?

Thank you!

Sincerely,

Susan

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.

Jeff

July 13, 2019at 3:49 am

Many Thanks Dear Pro Attaullah for this useful command!

I have one concern with 2×2 table and the use of text option to report Chi2 and p value. Is there any way to round or specify decimal points of the Chi2 and p value to be reported in MS word file?

    Attaullah Shah

    July 13, 2019at 3:56 am

    Jeff
    Here is one example

    sysuse nlsw88, clear
    asdoc tab married grade, replace
    tab married grade, chi
    local chi2 : di %9.3f = `r(chi2)'
    asdoc, text(Chi2 = `chi2')

Jeff

July 15, 2019at 12:21 am

Thank you! It works perfectly !!

Best regards !

pooja

July 19, 2019at 1:53 pm

hi..how to convert the following output on STATA in proper tables these are t tests results and i want to report for both type of households
ttest sex_hh, by(for_remitt_hh)
ttest age_group_hh, by(for_remitt_hh)
ttest edu_hh, by(for_remitt_hh)
ttest eco_activity_hh, by(for_remitt_hh)
ttest married_hh, by(for_remitt_hh)

    Attaullah Shah

    July 20, 2019at 12:16 am

    The help file of asdoc provides a largen number of example to generate elegant tables from ttest command. To see these example, type

    help asdoc

    and then navigate to the section 8

Michael

August 6, 2019at 2:37 pm

Dear Prof. Attaullah,
Thank you so much for providing us this wonderful command. I have been using esttab for years and asdoc is much better.
I ran into this problem and I haven’t seen similar cases in the discussion here.
When I output my crosstab, Word separates each row and add an empty row in between. Each row becomes a separate table. And the last column do not line up.

here is a simple example

  asdoc ta bilat, replace

bilat 	Freq.	Percent	Cum.

0 	164,126	   89.930	   89.930

1 	18,386	   10.070	  100.000

Total 	182,512	  100.000

Could it be my Word’s problem? I use traditional Chinese on my computer.

    Attaullah Shah

    August 9, 2019at 12:46 pm

    Michael
    This should not happen as asdoc creates aesthetically pleasing tables from tabulation commands. To see what might be going on on your computer, can you please send the following to my email attaullah.shah@imsciences.edu.pk
    1. The dataset
    2. The command you used
    3. The output generated by asdoc

Leave a Reply

five − 2 =