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

27 Comments

  1. Federico Podesta December 5, 2018 at 7:54 pm - Reply

    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!

  2. Anne Marie Schak Jensen December 7, 2018 at 5:47 pm - Reply

    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, 2018 at 5:50 pm - Reply

      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.

  3. Anne Marie Schak Jensen December 12, 2018 at 7:24 pm - Reply

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

  4. Richard Makurumidze April 7, 2019 at 3:18 am - Reply

    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, 2019 at 11:06 am - Reply

      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.

  5. YZ April 16, 2019 at 9:17 pm - Reply

    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, 2019 at 9:41 pm - Reply

      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)')
  6. Jiaqiong (Susan) Xu, PhD May 16, 2019 at 9:32 pm - Reply

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

    But I have a question. I just used your data and an example (for 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, 2019 at 9:36 pm - Reply

      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.

  7. Jeff July 13, 2019 at 3:49 am - Reply

    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, 2019 at 3:56 am - Reply

      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')
  8. Jeff July 15, 2019 at 12:21 am - Reply

    Thank you! It works perfectly !!

    Best regards !

  9. pooja July 19, 2019 at 1:53 pm - Reply

    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, 2019 at 12:16 am - Reply

      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

  10. Michael August 6, 2019 at 2:37 pm - Reply

    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, 2019 at 12:46 pm - Reply

      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

  11. Albert Botchway, PhD October 11, 2019 at 10:12 pm - Reply

    Hi Professor Shah,

    Thank you for asdoc. It really saves me time. I was wondering if there is a way to include a question mark in a title

    If I run, asdoc tab q8i, ///
    save(report.doc) title(How often do you read the Educational weekly email(sent on Tuesdays)?) fs(12)

    It gives me a nice table but there is no question mark in the title. Any suggestions on how to fix this?

    • Attaullah Shah October 11, 2019 at 10:14 pm - Reply

      The problem is not with the question mark, it is with the parentheses. Since asdoc uses opening and closing parentheses for parsing, they are not directly allowed as a text. So if you type the command like this, it will export the question mark

      asdoc tab q8i, save(report.doc) ///
      title(How often do you read the Educational weekly email sent on Tuesdays?) fs(12)

      Please 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.

  12. G December 6, 2019 at 9:14 pm - Reply

    Can I use asdoc with mrtab?

  13. Brian January 21, 2020 at 2:04 pm - Reply

    Dear Attaullah,

    Thank you for releasing and maintaining asdoc. When I use asdoc to report frequency, tabulate option ‘sort’ cannot be recognized by asdoc. Here attached is the codes.
    . asdoc tabulate var1, sort save(draft.rtf) append
    option sort not allowed

  14. Alonso March 28, 2020 at 2:50 am - Reply

    same problem :/

  15. Attaullah Shah March 30, 2020 at 11:30 pm - Reply

    Thanks for reporting it, I shall work on it and update asdoc.

  16. Daniella Acker April 7, 2020 at 2:50 pm - Reply

    Hello, very many thanks for providing this program, and I have noted the request to cite its use.

    A small issue which might interest you to look at is that ‘if’ following the ‘table’ command doesn’t seem to be recognised. eg ‘asdoc table mv if sales>1000000, contents(mean assets)’ tabulates all the observations, not the subset required. I might be doing something wrong but I’ve tried various versions of this with the same result. I can obviously deal with the problem by creating appropriate new variables but I thought it might be an easy one to fix in the program.

  17. Attaullah Shah April 8, 2020 at 4:54 pm - Reply

    Daniella Acker
    Please check the updated version of the asdoc. I checked it and did not find an issue.
    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.

    sysuse auto
    asdoc table rep78 if foreign == 1, replace
    
    ----------------------
    Repair    |
    Record    |
    1978      |      Freq.
    ----------+-----------
            3 |          3
            4 |          9
            5 |          9
    ----------------------
  18. Daniella Acker April 8, 2020 at 8:57 pm - Reply

    Many thanks – so sorry to have picked up the wrong version.

  19. user July 4, 2020 at 2:01 pm - Reply

    Just so you know, even in the latest version on SSC, when svy is used asdoc will only produce cell and col output not row with two-way tabulations. E.g. asdoc svy, subpop(rural): tab sex race, row percent format(%9.3g) will produce cell percentages instead of row percentages

Leave A Comment