asdoc : options and examples

  • 14

asdoc : options and examples

Category:asdoc,Stata Programs Tags : 


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

Example 3 : Naming the output file

asdoc sum, save(summary.doc)
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

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



Nicola Deghaye

June 19, 2018at 7:05 am

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)

H Panta

October 9, 2018at 5:30 pm

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, 2018at 6:44 pm

    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.


October 22, 2018at 1:34 am

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, 2018at 1:59 am

    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.


December 10, 2018at 10:56 am

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.

    Attaullah Shah

    December 10, 2018at 12:49 pm

    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.


December 11, 2018at 3:34 am

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, 2018at 3:43 am

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

Fabio Motoki

January 5, 2019at 7:55 pm

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, 2019at 10:26 pm

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


January 8, 2019at 11:39 pm

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, 2019at 7:07 am

    Thanks for the suggestion, I shall work on it.


January 12, 2019at 7:32 am

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

Leave a Reply

13 − 10 =