asdoc : Sends Stata output to MS Word

  • 57

asdoc : Sends Stata output to MS Word

Category:Stata Programs

About asdoc

asdoc is a Stata program that makes it super-easy to send output from Stata to MS Word. asdoc creates high quality, publication-ready tables from various Stata commands such as summarize, correlate, tabstat, cross-tabs, regressions, t-tests, flexible table, and many more.


The program can be installed by typing the following from the Stata command window:

ssc install asdoc, update

Table of contents

1. Introduction

1.1 asdoc: short introduction and examples
1.2 Commands for controlling asdoc


     2. Summary Statistics

2. Summary statistics
2.1 Basic summary statistics
2.2 Customized summary statistics

     3. Correlations

3. Correlations [Blog Post]
3. Correlations [YouTube Video]


4. Regressions

       4.1 Full regression tables [YouTube Video]

4.1.1 Customizing the detailed table: Stars and CIS
4.2 Compact / nested tables (publication quality)
4.3 Regression over a grouping variable (YouTube Video)
4.4 Changing order of variables in the nested regression table

     5. Frequency tables

5.1 One-way tabulation (tabulate1)   Watch YouTube Video
5.2 Two-way tabulation (tabulate2) Watch YouTube Video
5.3 One- and two-way tables of summary statistics (tabsum)
5.4 Multiple-way tables (tab1)
5.5 All-possible two-way tables (tab2)


6. Compact tables (tabstat)

6.1 Without groups
6.1 With groups


7. Flexible table of statistics (table)

7.1 One-way table
7.2 Two-way table
7.3 Three-way table
7.4 Four-way table


8. T-tests

8.1 one-sample t-test
8.2 two-sample using groups
8.3 two-sample using variables
8.4 paired t-test


9. Table of means, std., and frequencies (tabsum)

10. Means
10.1 Arithmetic / harmonic / geometric means
10.2 Proportions
10.3 Ratio
10.4 Total

11. Exporting the Stata Data with the sub-command list 

12. Writing matrix to a Word / RTF file

13.The survey prefix command

14.Customized tables with option row

15.Customizing Table Titles – Tips and Tricks


Nicole Martin

January 10, 2018at 8:37 am

Firstly, thank you for making your Stata package available – it’s really speeding up my workflow compared to the other options available. I’m writing to make a suggestion that you consider adding an option that value labels can be reported in regression tables as well as variable labels.

Joanna Dipnall

June 1, 2018at 3:42 am

I was very excited to find your wonderful asdoc Stata command. However, I am having some issues when wanting to create some tables. The Stata value labels not being copied in tab2.

For example the value labels with foreign are not copied into my Word file:

    Attaullah Shah

    July 27, 2018at 6:23 pm

    In version 2 of asdoc, I have included value lables with all tabulation commands, i.e. tabulate, tabulated2, tab1, tab2, etc. Thanks for your suggestion.

    Attaullah Shah

    August 26, 2018at 11:06 am

    Dear Joanna
    In version 2.0 of asdoc, option label has been added for the following Stata commands when using asdoc.
    1. tabulate
    2. tabulate2
    3. tab1
    4. tab2
    5. regress and all other variants of regressions in Stata

    You can update asdoc from SSC by:
    ssc install asdoc, replace

Oscar Briones

June 10, 2018at 3:35 pm

Many thanks indeed for the “asdoc” asdoc command stata
it has helped me alot.

Richell Onnel

June 19, 2018at 10:18 pm

Thanks very nice blog

Matthew Millard

September 22, 2018at 2:16 am

I have been telling everyone about the asdoc package who uses Stata. Several people told me how much they absolutely love it. One’s exact words were that it is “game changing” for convenience.

Parek Agustino

October 7, 2018at 10:47 pm

Found this absolutely helpful. Any chance of a MacBook version(Numbers)?

Attaullah Shah

October 8, 2018at 4:29 am

Parek Augustino: asdoc can be installed on any platform where Stata is installed.

HN Panta

October 13, 2018at 4:52 pm

Hello Dr. Shah,
Thank you so much for making stata help available publicly. I am trying to create a mean and median difference between two groups with test statistics (including starts). Could you help me with this?

HN Panta

October 13, 2018at 11:19 pm

Thank you so much! I’ll send you my query soon.

Ruth-Alma Turkson-Ocran

October 24, 2018at 1:08 am

I was wondering if your asdoc program can handle survey data. I do not see the info on your blog regarding using it with the survey command (there is no hyperlink for it here: In addition,
Only one output gets put into the table when I try the following command:

foreach v of varlist married edu_cat poor2 emp_stat notcov usupl stay_us{ 
asdoc svy, subpop(if black_african==1): tab `v' sex_r, count col format(%12.0g), append

    Attaullah Shah

    October 24, 2018at 1:14 am

    Ruth-Alma: Yes asdoc can work with svy commands. Please update asdoc and it will likely solve the problem you are referring to.

    ssc install asdoc, replace

Gemechis Mersha

November 6, 2018at 3:06 pm

I would like to say thank you for your asdoc work. I found it very helpful. But I get difficulty in applying asdoc to transfer Marginal Effect result to MS Word. All the command for regression is not applicable for Marginal Effect.

For example

asdoc reg x y, replace dec(3))

…..the command dec(3) works here
but didn’t work in

asdoc margins, dydx(*), replace dec(3)

is there any asdoc special command for transferring Marginal Effect result to Word?

Dr.Öğr.Üyesi Erkan Alsu

November 23, 2018at 1:35 pm

Hi Mr. Shah I congratulate you for your asdoc program. Very nice program. I am grateful to you for bringing such a program to the world of science. Where can I find the text file on Youtube video? Where can I find the asdoc Stata codes? Thank you. Yours truly.

    Attaullah Shah

    November 23, 2018at 1:39 pm

    Thanks for your kind words. asdoc can be installed from within Stata when you are connected to the internet. Type the following in the Stata command window

    ssc install asdoc

    After installation, you can find all the help and examples in the help file. To access the help file, type

    help asdoc

Joyce Lee

November 30, 2018at 12:48 pm

Hi Dr. Shah,
I absolutely love your program, and I cannot thank you enough! I just only would like to ask how I might be able to adjust the number of stars for significance level. I would like to add asterisks with regression coefficients such that

*** are added for p<0.05, 
** for p<0.01%, and 
* for p<0.001 level of significance

. It would be of great help. Thank you!

    Attaullah Shah

    November 30, 2018at 12:52 pm

    Joyce Lee: I am working on a dozen of options to add to asdoc in its next update. I have noted your suggestion and would consider it in the next update.


December 10, 2018at 1:43 am

Hi Professor, thank you for the great program. Quick question. When I try the following command (to include year dummy):

asdoc xi: xtabond var var

, the program says no variable named xtabond. Doesn’t the program support ‘xi:’ command yet? Thank you.

Attaullah Shah

December 10, 2018at 3:17 am

Rully: Thanks for reporting this bug. I shall try to find a workaround in the next update.


December 10, 2018at 6:41 am

Thank you Professor. It’s a great program.


February 12, 2019at 3:13 pm

Hi Professor,
Is it possible for asdoc command to be in the foreach loop?

    Attaullah Shah

    February 12, 2019at 5:17 pm

    Yes, asdoc can be used in foreach loop. Please elaborate what do you want to get at the end of the loop?


February 23, 2019at 5:07 pm

Hi Attaullah,

Thank you very much for your help. What is the stata code when we want summary statistics by year (for a panel data) using asdoc command? How can also export the asdoc document to any directory we wanted?


February 23, 2019at 5:07 pm

Hi Attaullah,

Thank you very much for your help. What is the stata code when we want summary statistics by year (for a panel data) using asdoc command? How can also export the asdoc document to any directory we wanted?

    Attaullah Shah

    February 23, 2019at 5:31 pm

    If you want to repeat the summary statistics by year, you can use the bysort prefix. see the following example,

    webuse grunfeld, clear
    bys year: asdoc sum, replace

    For your second query, you can use the save() option of asdoc. So assume that you have a directory in C:/results and you want to save the output to this directory. You would use the save option as shown below.

    webuse grunfeld, clear
    bys year: asdoc sum, replace save(C:/results/Myfile.doc)

Abdul Hameed Leghari

February 23, 2019at 5:26 pm

I hope you are doing great and feeling healthy. I’m writing this to congratulate to you on your STATA Program (asdoc). I have been utilizing STATA for a long time. This is such a major achievement in STATA history. It appears to be extremely valuable for me and it has tackled a significant number of my issues. I have been working in the development sector throughout the previous five years. I have performed several nationwide survey analysis, for example, Pakistan Panel Rural Household Survey, Pakistan Agriculture Survey, Pakistan Household Skills Measurement Survey and Operational Review of the Waseela-e-Taleem Programme, and so on. As of now, I have used it with many STATA commands and it effectively sends STATA yield to MS Word in extraordinary looking tables. I again acknowledge and compliment you for this work and pray for your successful and effective future.

Abdul Hameed Leghari
Senior Economic Analyst


March 9, 2019at 3:05 pm

How can I remove the compounded exported output by asdoc from STATA? Thanks

    Attaullah Shah

    March 9, 2019at 4:13 pm

    Can you please elaborate your query?


March 9, 2019at 4:18 pm

Good day sir, I exported output from Stata using asdoc and subsequently I attempted to export new output from different data, but even all those ones I initially exported were included in with new output.
I only want the exportation to be solely on a particular Data at a time, not a combination of previous data output in the ms word

    Attaullah Shah

    March 9, 2019at 4:32 pm

    OK, there are two way in which you can separate outputs from differet Stata commands:

    (1) Use replace option, that will replace the existing file. However, you should have copied or renamed the file otherwise the contents of the existing file will be replaced.

    (2) A better option would be to use the save(file_name) option. This way you can save each output in a sseparate file.

    See this example

    sysuse auto, clear
    asdoc sum, save(summary)
    asdoc cor, save(cor)

    The above code would generate two files one with the name summary.doc and the second with the name cor.doc

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


March 10, 2019at 1:57 am

I’m trying to use asdoc to save a collection of tables made with bysort and sum but it says to many variables are specified. Is it possible to use asdoc on something like
bysort 1 2: summarize 3 4 5 6 7 8

    Attaullah Shah

    March 10, 2019at 10:07 am

    If you want to use more than one variable in the bysort prefix, then you can first group those variables into one using the group function of egen command. Then use the new variable in the bysort prefix. In the following example, I have grouped the variables rep78 and foreign and find summary statistics for all numeric variables using the new variable grouped as grouping variable.

    sysuse auto, clear
    egen grouped = group(rep78 foreign)
    bysort grouped : asdoc sum

    If you find asdoc useful, please cite it 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.


March 21, 2019at 7:56 pm

Dear Professor,

I am trying to use “asdoc” with tabulate command. I obtain the following error:

. asdoc tabulate implementing_jurisdiction, replace

option matrow() not allowed

    Attaullah Shah

    March 21, 2019at 8:17 pm

    Can you please a sample of your data at
    Please also send the following info:
    the version of asdoc, which can be found by typing

    which asdoc

    2. Which operating system do you use? i.e. windows, MacOs or other
    3. Which Stata version

    Attaullah Shah

    March 24, 2019at 11:02 pm

    Thanks for providing the dataset. It seems the variable implementing_jurisdiction is a string variable. If a variable does not have value labels, the mentioned error is returned by asdoc. In order for asdoc to work, we first need to conver the variable to a numeric format with value labels. The good news is that we can do that in one line of code. In the following code, I convert the mentioned variable to numeric format and generate a new variable, called num_ij, then use asdoc with the new variable

    encode implementing_jurisdiction , gen(num_ji)
    asdoc tabulate num_ij, replace

    And there you go.

    Please cite asdoc in your research:


March 24, 2019at 9:26 pm

Dear Attaullah Shat

I am getting the same error as Roland citing “Roland
March 21, 2019at 7:56 pm
Dear Professor,

I am trying to use “asdoc” with tabulate command. I obtain the following error:

. asdoc tabulate implementing_jurisdiction, replace

option matrow() not allowed

I am also getting this error:
astable(): 3301 subscript invalid
: – function returned error

I am using Windows 10, Stata MP 64 bit, asdoc version is ->

    Attaullah Shah

    March 24, 2019at 11:08 pm

    I hope the solution I presented above will also work for you. In the future updates, I shall try to add support for string variables inside asdoc, but for time being, the workaround of encode should effectively solve the problem.


April 5, 2019at 8:08 pm

Hi Sir,

Does the label option works for logit? I tried to use the label option with logit, but it doesn’t work…

    Attaullah Shah

    April 5, 2019at 10:51 pm

    I have checked and option label works fine with logit. I am using version of asdoc. You can check your version of asdoc by

    which asdoc

    An example of option label with logit is given below.

    webuse lbw
    asdoc logit low age lwt i.race smoke ptl ht ui, replace label


April 6, 2019at 1:13 am

I am using How could I update it ?


April 6, 2019at 1:15 am

I used ssc install asdoc, replace, but still getting


April 6, 2019at 7:46 am

I think the question was wrong. I get the label for continuous variables but not for categorical variables (I mean about the independent variables). Also I tried the code you provided, but I got the label values for the continuous variables, but not for the race.

    Attaullah Shah

    April 6, 2019at 8:17 am

    Can you please send your data and Stata code at
    Also, please indicate in your email what is not working for you and is going against your expectations.


April 9, 2019at 6:37 pm

Dear Professor Shah,

I installed the latest version of the ‘asdoc’ ADO file. I am using Stata offline due to data confidentiality. So, the asdoc file is called from a folder in C drive.

The problem is that when I try to run different Stata commands, I keep receiving the following error:
” astable(): 3001 expected 5 arguments but received 12
: – function returned error”

In particular, the commands (e.g. “asdoc table” or “asdoc tabulate”) are executed normally by Stata and tables are created in the Stata window. However, instead of showing the “Click to Open File: Myfile.doc” line, the abovementioned error appears, so I cannot extract the tables in Word. Could you please explain why this happens and provide possible remedies? With the previous version of asdoc (November 2018), I did not face such issues.

Thank you and best wishes,

    Attaullah Shah

    April 9, 2019at 6:42 pm

    Since you installed asdoc manually, now it seems there are two versions of asdoc on your system, one old and new. The function library gets confused among these versions. You should first uninstall asdoc completely using the following code, then reinstall asdoc and then restart your Stata.

    net install uninstall_asdoc, from( replace
    ssc install asdoc, replace


April 9, 2019at 7:27 pm

Dear Professor Shah,

Thanks for your prompt reply.
I am not the person who does the installation but the data providers do this (as I cannot access the internet from their server, but I only access the data remotely through their working space).

I can only see 2 files in the folder from which asdoc is called: 1. “asdoc.ado (ADO file)” and 2. “asdoc (Stata SMCL document)”.

Nothing is currently installed in my Stata. Every time I start Stata, I have to install Asdoc (by calling it from the folder mentioned above using the ‘findit’ command).

I was wondering whether perhaps not all necessary asdoc files are stored in that offline folder, so that is why the errors appear? For example, again when I run the “asdoc tabulate” command I receive the following error: “: 3499 asdoc_tab_onevar() not found”.

Could you please name the files that I need to have in place in order to have a complete installation of asdoc? I will then inform the data providers accordingly to download these files.

Thanks again,

    Attaullah Shah

    April 9, 2019at 10:49 pm

    Actually, there are three files, which are
    1. asdoc.ado
    2. asdoc.sthlp
    3. lasdoc.mlib

    The last file is missing from your system and the same old file is used by Stata which has a different function structure than the updated one. Drop me an email at and I shall email you these files.


May 14, 2019at 2:34 pm

Dear Professor Shah,

for me, it is only possible to use Stata offline. Is it still possible to somehow install the asdoc command?

Thank you

    Attaullah Shah

    May 14, 2019at 2:47 pm

    Finja: You can download the installation files from RePEC IDEA page, second tab with the title Download. Once downloaded, then place these files in relevant folders: So the asdoc.ado and asdoc.sthlp files will go in the following folder


    The third file lasdoc.mlib will go into the following folder


    Where the last letter is small L.


May 30, 2019at 9:56 am

Hi, I love asdoc but am getting the following problem when trying to write estat class after logistic to a word file:
subinstr(): 3200 conformability error
asdocrest_custom(): – function returned error
: – function returned error

Also, is it possible to write the confidence intervals instead of se for my nested table?
Thank you.

    Attaullah Shah

    May 31, 2019at 2:56 pm

    Please post the full Stata code, i.e what did you write and what did Stata say?


June 5, 2019at 6:38 pm

Dear Professor Shah,
Is it possible to use asdoc using 3sls regression?

Looking forward to your reply.


    Attaullah Shah

    June 7, 2019at 8:47 pm

    I have added support for 3sls regressions in asdoc.

    This beta version can be installed from my site.

     net install asdoc, from( replace

    An Example

    Since the 3sls command has a complex syntax structure, I have separated it from asdoc. So first we shall enter the full 3sls command and then use replay command with asdoc. See the following example.

    webuse klein, clear
    reg3 (consump wagepriv wagegovt) (wagepriv consump govt capital1)
    asdoc replay, nest replace
    reg3 (consump wagepriv wagegovt) (wagepriv consump  capital1)
    asdoc replay, nest

Esteban Arellano

June 10, 2019at 8:02 am

Dear professor Shah,

I am using svy with asdoc, but I am creating weighted tables with

asdoc svy: tabulate cedad csexo, count format(%14.3gc)

and I get this answer “option count not allowed”, help with this issue please.

Attaullah Shah

June 10, 2019at 11:24 am

Esteban Arellano
Adding weighted statistics to svy command would need some good amount of coding and hence I have postponed them until I find enough time for it. Thanks for reminding.

Leave a Reply

18 + 5 =