Introduction

asdoc sends Stata output to Word / RTF format. asdoc creates high-quality, publication-ready tables from various Stata commands such as summarize, correlate, pwcorr, tab1, tab2, tabulate1, tabulate2, tabstat, ttest, regress, table, amean, proportions, means, and many more.

Using asdoc is pretty easy. We need to just add asdoc as a prefix to Stata commands. asdoc has several built-in routines for dedicated calculations and making nicely formatted tables.

asdoc Options

How to enter asdoc options and Stata_command options?
Both the asdoc options and Stata_command specific options should be entered after comma. asdoc will parse both the option itself. For example,the following command has both types of options.

asdoc sum, detail replace dec(3)

option detail belongs to sum command of Stata, whereas options replace and dec(3) are asdoc options.

Following options are used for controlling the behavior of asdoc:

1.1 Replace / append:

We shall use option replace when an existing output file needs to be replaced. On the other hand, we shall use option append if we want to
append results to the existing file. Both the options are optional. Therefore, if none of these options are used, asdoc will first determine
whether a file with a similar name exists in the current directory. If it exists, asdoc will assume an append option. If the file does not
exist, it will create a new file with the default name “Myfile.doc”

Example 1 : running asdoc without replace or append (first time)

sysuse auto
asdoc sum

The above lines of code will generate a new file with the name Myfile.doc. Next, if we estimate a table of correlation, we can replace the
existing file Myfile.doc or append to it. Again, if we do not use any of these options, option append will be assumed. So;

Example 2 : running asdoc without replace or append (second time)

asdoc cor
OR
asdoc cor, append

Both of the above commands serve the same purpose. The file Myfile.doc will now contain a table of summary statistics, followed by a table ofcorrelations. However, had we typed the following, then the file would contain only table of correlations. asdoc cor, replace

1.2 rowappend:

To develop a table row by row from different runs of the asdoc, we need to use option rowappend. This option can be used with ttest, customized summary statistics, or in other instances where the table headers and structure do not change
and appendable statistics have a similar structure as those already in the table.

1.3 save (file_name):

Option save(file_name) is an optional option. This option is used to specify the name of the output file. If left blank, the default name will
be used, that is Myfile.doc. If .doc extension is not preferred, then option save will have to be used with the desired extension, such as
.rtf

Example 3 : Naming the output file

asdoc sum, save(summary.doc)
OR
asdoc sum, save(summary.rtf)

1.4 title(table_title)

Option title(table_title) is an optional option. This option is used to specify table title. If left blank, a default table title will be
used.

asdoc sum, save(summary.doc) title(Descriptive statistics)

1.5 Font size i.e. fs(#)

The default font size of asdoc is 10 pt. Option fs(#) can be used to change it. For example, fs(12) or fs(8), etc.

1.6 Decimal points i.e. dec(#)

The default decimal points in many commands are 3. In some commands, the decimal points are borrowed from the Stata output and hence they cannot be changed. In several commands, it is possible to change decimal points with option dec(#). For example, dec(2) or dec(4), etc.

1.7 Adding text lines to the output file i.e. text(text lines)

We can write text to our output file with option text(text lines). This is useful when we want to add details or comments with the Stata
output. In fact, this option makes asdoc really flexible in terms of adding tables and paragraph at the same time. We never have to leave the
Stata interface to add comments or interpretation with the results. One trick that we can play is to use option fs() to change font size and
mark headings and sub-headings in the document. Consider the following examples [I have copied some text from www.wikipedia.org for this example]

1. Write a heading "Details on Cars" in our document
asdoc, text(Details on Cars) fs(16) replace

2. Now add some text

asdoc, text(A car is a wheeled motor vehicle used for transportation) append fs(10) 
asdoc, text(Most definitions of car say they run primarily on roads, seat one ) append fs(10) asdoc, text(to eight people, have four tires, and mainly transport people.) append fs(10)

3. Now add some statistics

sysuse auto, clear
asdoc sum, append fs(10)

1.8 Hide Stata output with option hide

We can suppress Stata output with option hide. It is important to mention that option hide might not work with some of the Stata commands (asdoc creates output from log files in some cases).

1.9 Getting Stata commands in output files (cmd)

If we need to report the Stata command in the output file, we can use the option cmd.

1.10 Abbreviate variable names with option (abb(#))

In case variable names are lengthy, they can be abbreviated in the output file with option abb(#). For example, abb(8). In many cases, the
default value is 10. However, when option label is used, this value is set to = abb + 22

1.11 Report variable labels with option (label)

Several commands allow reporting variable labels instead of variable names. For example, the most commonly used commands for reporting statistics are correlate and summarize. Both of these commands allow option label. For example :

asdoc cor, label
asdoc sum, label

1.12 Always report equal decimal points (tzok)

The default for report decimal points is to drop trailing zeros and report only valid decimal points. However, we can use the option tzok
i.e. trailing zeros OK, to report equal decimal points for all values even if the trailing values are zero. Therefore, using option
dec(4) for reporting 4 decimal points, the value 2.1 will be reported as follows with and without option tzok.

Default style 2.1
with tzok option 2.1000

[addthis tool=”addthis_relatedposts_inline”]

34 Comments

  1. Nicola Deghaye June 19, 2018 at 7:05 am - Reply

    I have tried to specify the number of decimal points to be used with the command “mean”, using asdoc. It doesn’t work. Is “mean” one of the commands where one cannot specify the number of decimal points to be used with asdoc? Or do you think I have made a mistake in my coding?
    Here is my code:

    asdoc mean num_trained if school_restrict==1   [fweight=school_wgt_rounded], over(Province) fs(11)  ///
    label dec(2)  title(Mean number of trained teachers per school, by province: 2011) append /// save(SMS2011_by_province.rtf)
  2. H Panta October 9, 2018 at 5:30 pm - Reply

    Hi,
    I really appreciate you for your hard work. I am just wondering if you have a sample for mean and median test for two groups in a sample. I want to create a summary table, including obs, mean and median with test stats and significance level for two groups.
    Thank you.
    H. Panta

    • Attaullah Shah October 9, 2018 at 6:44 pm - Reply

      Hi H Panta
      You can use the stat option with the sub command sum and report customized statistics. For example, from the auto dataset, let us create the statistics you have specified for a list of variables

       sysuse auto
      asdoc sum price trunk weight turn, stat( N mean p50 tstat) 

      In the above code, the term p50 is used for reporting the median.

  3. Giovanni October 22, 2018 at 1:34 am - Reply

    It would be nice to be able to suppress the title when producing many one-way freq. tables. Also, would be cool if ‘rowappend’ worked with tab1.

    • Attaullah Shah October 22, 2018 at 1:59 am - Reply

      Giovanni : The title can be suppressed by entering an empty title. You can also see this thread on the Statalist, post 35 where I showed how to do it. Here is a short example:

      sysuse auto, clear
      asdoc tab rep78, title(\) 

      The title(\) is a way of entering an empty title. And thanks for the rowappend option, I shall explore this possibility in the next update.

  4. HP December 10, 2018 at 10:56 am - Reply

    Hi,
    Is there a way to put stars for significance ttest by group?

    asdoc ttest mpg, by(foreign) replace

    how to put stars for the difference?
    Can we find the median difference between mpg by a group like foreign using asdoc?
    Thank you for your support in advance.
    HP

    • Attaullah Shah December 10, 2018 at 12:49 pm - Reply

      HP: Adding significance stars to t-test results is not currently supported by asdoc. I was waiting for someone to ask for it, you are the first one. I shall try to add it to asdoc in the next update. Thanks for stopping by and your comments.

  5. HP December 11, 2018 at 3:34 am - Reply

    Thank you for the prompt response. Would you be able to add a median test by the group so that that we can find the median difference of a given variable in two groups? Thanks.

    • Attaullah Shah December 11, 2018 at 3:43 am - Reply

      HP: Please provide some example or refer me to some material on what you are asking for

  6. Fabio Motoki January 5, 2019 at 7:55 pm - Reply

    Thanks for asdoc! It is a great tool! However, could you add the option to put the number of observations at the end of the correlation table? I usually put it when using estpost correlate / esttab, but I could not find out how to do it with asdoc.

    • Attaullah Shah January 5, 2019 at 10:26 pm - Reply

      Fabio Motoki Can you please suggest a layout in which the number of observations would be appended to the correlation table?

  7. Anonymous January 8, 2019 at 11:39 pm - Reply

    Hi,
    Just like finding the mean difference between two groups as

    asdoc ttest mpg, by(foreign) replace

    can we test median difference as

    asdoc ranksum mpg, by(foreign) replace
    • Attaullah Shah January 9, 2019 at 7:07 am - Reply

      Thanks for the suggestion, I shall work on it.

  8. Besio January 12, 2019 at 7:32 am - Reply

    Just wanna input on a couple of comments. This site layout is perfect, the articles are quite superb:

  9. Lauren March 16, 2019 at 1:10 am - Reply

    Thanks so much for your hard working on this! It’s a great way to output tables from Stata. Is there a way to change the font size for a table title? The fs() option seems to only change the size of the text in the table, not the title.

    • Attaullah Shah March 16, 2019 at 6:59 am - Reply

      Lauren
      Thanks for your feedback. Yes, it is possible. In fact, we can pass any RTF control word for formatting the title text. For changing the font size, relevant control word is fs. See the following example where I set the font size 40 for the title text.

      sysuse auto
      asdoc sum, title(\fs40 My descriptive)
  10. William April 9, 2019 at 8:28 pm - Reply

    Hi,

    asdoc was very helpful during the last day, but currently I am having some trouble.

    If I try to use asdoc to export a correlation diagram I get the following error: “: 3499 asdoccor() not found”

    Do you have any idea how I could solve this or is anybody else have the same problem?

    • Attaullah Shah April 9, 2019 at 10:53 pm - Reply

      William: This is rather an unusual error message, please re-install your package by typing

      ssc install asdoc, replace

      And restart your stata. If that does not solve the problem, then please send me the following:
      1, Type the following and send me the output

      which asdoc

      2. Also, please indicate which version of Stata and operating system do you use

      3. Please if you can share your data set or a sample of it

      Email: attaullah.shah@imsciences.edu.pk

  11. Muvanhu January 13, 2020 at 12:40 am - Reply

    Hello, how do I create a table of summary statistics using asdoc of selected variables, for example my data has 12 variables but I just want the statistics of 6 variables only. Thank you for your help

    • Attaullah Shah January 13, 2020 at 8:09 am - Reply

      Muvanhu
      You have to write the names of those variables. For example, in the following code, I am specifying three variables, ie. price, mgp, and rep78
      sysuse auto, clear
      asdoc sum price mgp rep78, replace

  12. Pricilla January 25, 2020 at 12:44 am - Reply

    Hallo, thanks for asdoc, great command! I am having issues saving my output results in a log file when my dofile has more than one asdoc command. If there is more that one asdoc command in the dofile, it does not save all the output results – the logfile breaks down somewhere and I get an error indicating there is no log file to close. However when I remove all the asdoc commands, the logfile saves everything in the output window and closes properly,… Is this something you have encountered or been asked.

    Hope the narrative I am giving is clear… .

    Thanks

  13. Sandra January 29, 2020 at 11:11 pm - Reply

    I am having the same problem as Pricilla. Asdoc seems to be interacting with the log command somehow. For now I am going to try to close the log file before every asdoc and then reopen it after. I would love a better solution.

  14. Edoardo February 10, 2020 at 2:46 pm - Reply

    Good morning professor Shah, I’m trying to combine the outputs of a t-test plus a summarize.
    using a piece of your code found on a Statalist post, I tried to replicate something like the following:

    ttest mean_age, by(stupd)
    
    *Get the relevant statistics
    loc obs1 = `r(N_1)'
    loc obs2 = `r(N_2)'
    loc mean1 = `r(mu_1)'
    loc mean2 = `r(mu_2)'
    loc dif = `mean1' - `mean2'
    loc stde = `r(se)'
    loc pval = `r(p)'
    dis `dif'
    
    sum mean_age if stupd == 0
    loc max1 = `r(max)'
    loc min1 = `r(min)'
    
    sum mean_age if stupd == 1
    loc max2 = `r(max)'
    loc min2 = `r(min)'
    
    *Write these with asdoc using the row option
    
    
    asdoc, row(`Age', `obs1', `obs2', `min1', `max1', `min2', `max2', `mean1', `mean2', `dif', `stde', `pval') replace

    unfortunately, the output is an empty table. could you point me the mistakes I’m making?

    thanks a lot in advance

  15. IM March 4, 2020 at 4:25 pm - Reply

    I want to drop coefficients of i.year i.indnu from my asdoc table. But drop does not work. I get the message that “drop is not allowed”. Can you help! Thanks

    • Attaullah Shah March 5, 2020 at 7:23 am - Reply

      Can you please post the full command?

  16. IM March 5, 2020 at 9:17 pm - Reply

    In response to your mail:

    asdoc xtreg l q r s g nta i.year i. indnu , ///
     fe robust save(myresults) fs(8) drop(year2014-2019  indnu1-indnu30) 

    My year variable contains 2014 to 2019. Industry variable includes names of industries (string variable) and is coded as follows;

    tabulate industry, generate(indnu)

    drop command does not work.

    Thanks

    • Attaullah Shah March 6, 2020 at 8:34 am - Reply

      IM
      You may use the keep() option as dummy variable names and factor variables are usually difficult to type and get their correct name. You may try this:

      asdoc xtreg l q r s g nta i.year i.indnu , ///
       fe robust save(myresults) fs(8) keep( l q r s g nta)

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

  17. IM March 7, 2020 at 7:01 pm - Reply

    Thanks a lot Prof Shah.
    For generating i.indnu, I use code:

    tabulate industry, gen(indnu)

    When I run code
    asdoc xtreg l q r s g nta i.year i.indnu, fe robust save(myresults) fs(8) keep(l q r s g nta)

    I ge message indnu ambiguous.
    When I generate indnu using: encode industry, gen(indnu) , I get results but coefficients of both year and industry do appear in in Table.

    I will appreciate your help.
    Thanks a lot

    • Attaullah Shah March 8, 2020 at 6:51 am - Reply

      Please send your dataset and your code at my email.

  18. Charlotte March 19, 2020 at 2:48 pm - Reply

    Dear Professor Shah,

    your asdoc command is helping so, so much. Thank you!

    I have a question. I am running a probit regression, hence I am not interested in the coefficients but rather in the marginal effects. Is there a way to include those instead for each variable and for each model?

    As of now I am running the following command:

    asdoc probit results players games goals, replace nest cnames(Model 1) dec(3) save(Regression_Table_Base_Model) title(Probit Regression Table) fs(8) stat(chi2)

    I would like to add the results of

    margins, dydx(*) atmeans

    to my table and drop the coefficients instead. The significants stars I want to keep, same as the standard errors.

    Thanks already
    Charlotte

  19. G.Ramakrishna April 24, 2020 at 5:57 pm - Reply

    I am running multilevel logit model. can we use asdoc to get the results in one table? If so how to proceed?

    • Attaullah Shah April 24, 2020 at 7:35 pm - Reply

      Dear Professor Ramakrishna
      Multi-level models are currently not supported by asdoc. The next version of asdoc (I call it asdocx) will have this missing functionality. I shall send an email to all asdoc users once the next version is read.

  20. Bill Nkeeto June 12, 2020 at 11:03 am - Reply

    Dear Dr. Shah,
    I must commend you for the good job with asdoc.
    My inquiry is about the cor output table that i had previously ran to establish which variables are highly correlated before going on for further analysis. When I proceeded with the analysis using the logit command after which I applied asdoc with the replace option, I still get the earlier collation matrix table. To further clarify, i ran a line of code with a logit model with at option to replace, i still got that previous cor output (matrix of correlation table). Is there anything I am not getting right

Leave A Comment