## How to export high-quality table of correlations from Stata to MS Word

Category:asdocFor creating a high-quality publication-ready table of correlations from Stata output, we need to install asdoc program from SSC first.

ssc install asdoc, update

Once the installation is complete, we shall add the word asdoc to the cor or correlate command of Stata. Since we estimate correlations among all numeric variables of a dataset with just cor, we shall add asdoc as a prefix to the cor command. For our example, purposes, let us load the auto.dta data from the Stata example files.

**Example 1: Make a table of correlation for all variables.**

sysuse auto, clear asdoc cor

**Example 2: We can report variable labels instead of variable names**

asdoc cor, label replace

Further, it is possible to write names of the variables in the column headings instead of sequential numbers. For this, we shall invoke the option **nonum.** Therefore, see example 3.

**Example 3: Write variable names in column headers**

sysuse auto, clear asdoc pwcorr, nonum replace

**Read also : **

Generate a correlation table with significance/stars

Generate a table of descriptive statistics

Generate a table of customized descriptive statistics

## 36 Comments

## Zhang Huang

November 12, 2018at 2:48 pmI can’t download asdoc from the stata. Can you help me and sent the asdoc.ado and asdoc.sthlp to me?

Thank you.

## Attaullah Shah

November 12, 2018at 2:50 pmTo download, type

ssc install asdoc

If you receive any error message, then please share that.

## Zhang Huang

November 12, 2018at 2:53 pmSorry. It always replies like this in Stata:

checking asdoc consistency and verifying not already installed…

`connection timed out -- see help r(2) for troubleshooting`

could not copy http://fmwww.bc.edu/repec/bocode/a/asdoc.sthlp

(no action taken)

r(2);

I think maybe because I am in China, so the download action is defined.

## Attaullah Shah

November 12, 2018at 2:55 pmOK, copy the attached files to the mentioned directories

copy asdoc.ado and asdoc.sthlp to this folder

2. Copy the lasdoc.mlib to this folder

The last letter is L in small.

## Simon

December 25, 2018at 5:44 pmHi Attaullah,

How can I get the star sign in the correlation number? Is it possible to get it using the asdoc command.

## Attaullah Shah

December 25, 2018at 6:50 pmSimon: The significance stars can be reported using the sub-command pwcorr. For example

## Simon

December 28, 2018at 5:33 pmHi Attaullah,

Many thanks for your reply. can we get also 0.05 and 0.10. I have tried with the given code but it does not work.

Regards,

Simon

## Attaullah Shah

December 28, 2018at 6:55 pmSimon: Reporting stars for showing statistical significance at .05 or 0.1 level works the same way as shown above. For example,

## Anonymous

January 1, 2019at 6:11 pmMany thanks Attaullah. I understand your point. But actually, my query was in one table, how we can generate all star sign for 0.1, 0.5, and 0.01. Similar like the correlation table published in the article. Sometimes, in one table, some variables may be significat at 1%, some at 5% and some at 10%.

Appreciate your help.

Thanks again.

Regards,

Simon

## Philipp

January 25, 2019at 7:32 pmThank you very much Attaullah. I have one question:

I have a lot of independent variables (41) in my correlation matrix. How can i prevent that asdoc exports them and needs more than the breadth of one page in word? In an ideal case i can tell asdoc to continue the correlation matrix at the next page.

Do you know if there is such an opportunity?

Thank you in advance!

Philipp

## Attaullah Shah

January 27, 2019at 8:34 amPhilippThanks for the suggestion. I never thought that one might need a correlation table for so many variables. I shall keep this in mind and work on it when I have some time.

## Philipp

January 28, 2019at 8:46 pmDear Attaullah. No worries. I dont want to estimate all of the variables within one model. With the large variable list i can show that for several combinations of variables serious issues of multicollinearity arise. Thereby i can justify my choosen model better.

## Professor Michael Glencross

March 19, 2019at 9:13 amDear Professor Shah

I have recently come across your excellent addition to Stata in the form of asdoc. Is there any way that it can be made compatible with Stata 11?

Kind regards

Michael Glencross

## Attaullah Shah

March 19, 2019at 9:15 amDear Michael GlencrossThe only reason asdoc does not support Stata 11 is that the Stata Corp. introduced the r(table) with regression commands in Stata 12 and onwards. Since asdoc creates regression tables from r(table) matrix, therefore, I restricted it to version 12 and onwards. Still, if you do not use asdoc for regressions, it can still work with Stata 11. So find asdoc.ado on your computer, open it with notepad or Stata do editor and delete the line version 12.

Restart Stata and it will work with Stata 11.

## Professor Michael Glencross

March 21, 2019at 12:45 pmDear Professor Shah

I have another query and hope you don’t mind me asking for your help again.

I have done as you said and removed the line version 12 from my asdoc.ado file.

I ran: asdoc tab gender and received the following error message:

asdoc_tab_onevar() in lasdoc, compiled by Stata 11.1, is too new to be run by this version of Stata and so was ignored

Is there something I can do to overcome this?

Your help will be much appreciated.

Kind regards

Michael Glencross

## Attaullah Shah

March 21, 2019at 12:47 pmasdoc Meta library was compiled with Stata 11.1, you can update your Stata for free to version 11.1

https://www.stata.com/support/updates/stata11.html

## Chris Boulis

April 13, 2019at 1:26 pmDr. Attaullah Shah .

I have just downloaded asdoc and am planning to capture the results from three pairs of regressions. Each pair regresses the same control variables, but changes the dependent variable (I have 2 measures of my depvar). Each pair works the same, but in each pair I assess the impact of a slightly different life event.

I’ve watched your youtube video which shows how to keep adding variables, but I was wondering how I do that in my case?

I’d like to produce a table where the rows included all the control variables (which as I said are the same for each regression) and across the columns have the three different life events – with two separate columns below each life event to show the results of my two measures of my depvar.

I would really appreciate your guidance on how I can do this using your package asdoc. I tried using outreg but copying the table to word in html format leaves a mess that will require a lot of time to make it presentable.

Kind regards,

Chris

## Attaullah Shah

April 13, 2019at 1:52 pmChris BoulisIt seems you need a wide regression table. In the help file of asdoc, which you can access by typing:

Go to Section 4.3.1 where I have shown all options and related examples of wide regressions. See the following example for quick start.

Please cite asdoc in your work:

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.## Chris Boulis

April 14, 2019at 3:50 amDr Attaullah Shah.

Thank you for your response. However, after I tried that, it moved all independent variables wide and only had the two measures of the depvar in rows, which results in the table being too wide. I need all the indepvars in the rows and each pair of depvars for each of the three life events across the columns.

The following is an example of the table I am trying to obtain from my six regressions (e.g.

Life event1 – depvar1, Life event1 – depvar2, Life event2 – depvar1, Life event2 – depvar2, Life event3 – depvar1, Life event3 – depvar2).

Kind regards,

Chris

## Attaullah Shah

April 14, 2019at 6:23 amChris BoulisIt seems you need a nested table, not a wide table. For nested tables, you need something like this. It would be much easier for me to code this if you can send me your data and regression commands at attaullah.shah@imsciences.edu.pk

## Chris Boulis

April 15, 2019at 6:30 pmDear Dr Attaullah Shah.

Thank you for your assistance. Unfortunately, I am using a very large panel dataset and not permitted to share sorry.

I used the following code and added several other regressions and was able to get close to what I wanted but I had to do a fair amount of formatting as it carried over the pre-recoded (original) variables names, but that’s ok. I need to finalise this for tomorrow. The output I have I have now is much better than using ‘outreg’.

etc.

What do you think?

Kind regards,

Chris

## Attaullah Shah

April 15, 2019at 6:33 pmDear Christopher

That’s OK if you canncot share your data. The commands you have typed seems in good shape. Just one comment on your line ”

`it carried over the pre-recorded (original) variables names, but that’s ok.`

” If you want you can replace variable names with variable labels using option label.## Nighat Seema

April 15, 2019at 8:03 pmDear Sir

Hope you are fine. I am facing some issue in output of corr matrix via asdoc. I am using the command

The output table attached below does not include the names of all the variables. Kindly suggest something in this regard. I will be really thankful to you.

Regards

## Attaullah Shah

April 15, 2019at 8:05 pmNighat SeemaThe variable names are abbreviated to save space. If you do not want abbreviated names, then use extend the allowed abbreviated characters with the option abb(). For example, in your command, I am attaching abb(72), that will accommodate up to 72 characters in the variable names

## Anders

June 25, 2019at 1:29 amProfessor,

The command asdoc it’s not working on my Stata. The system shows as result: asdoc pwcorr lg lc ls ebitda roa roe etr nm ativt pl

(note: file Myfile.doc not found)

What’s wrong?

Thank you!

## Attaullah Shah

June 28, 2019at 7:49 pmAnders

It seems an installation issue. Please install asdoc again by

If that does not solve the problem then please send me your data, the code that you used with asdoc and tell me whether you are using Windows or MaCOs. My email is attaullah.shah@imsciences.edu.pk

## Sanna

June 28, 2019at 7:36 pmDear Professor,

The command asdoc it’s not working properly on my Stata either. When I call for corr it works:

<pre>asdoc corr Q6_työ_paha Q36_vie_mukanaan , sig star(*0.10 **0.05 ***0.01) save(K:\My Documents/korrelaatiot.doc) append

(obs=5,757)

But when I call for pwcorr it doesnt work:

Could you please help me

Thank you!

## Attaullah Shah

June 28, 2019at 7:45 pmSanna

You are using the star() option incorrectly. If you want to report stars for statistical significance, then you need to type star(all). See

Sidenote: The sig option renders the table rather untidy, so if you are reporting stars, the sig option is really not needed.## Andreas

July 3, 2019at 4:02 pmDear Dr. Shah,

this is a great addition to Stata and has helped me very much. I have one small question concerning the significance stars in the correlation matrix. Right now, if I use the star(all) command, it will add stars for significance at .1, .05 and .01 level. Is there any way I can change this so that it will add stars at .05, .01 and .001 level instead?

Thank you in advance for your time and help!

## Thomas

July 3, 2019at 11:34 pmDear Sir,

I have the same problem as Anders.

The command is working with corr, but for pwcorr I do get an invalid name error r(198).

pwcorr without asdoc is working however.

The weird thing is, that this worked just fine in the past and I din’t change the code.

Thanks for your help

## Attaullah Shah

July 3, 2019at 11:38 pmThomas

The error was fixed recently. The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.

Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

Please do remember to cite asdoc. To cite:

In-text citationTables were created using asdoc, a Stata program written by Shah (2018).

BibliographyShah, 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.

## Thomas

July 4, 2019at 9:54 pmThanks for the quick response sir,

however I still get the invalid name error.

I am using Stata 15.1 if that makes a difference?

kind regards Thomas

## Attaullah Shah

July 5, 2019at 12:16 amThomas

Can you please send your data and the code that you are using at my email attaullah.shah@imsciences.edu.pk

## Attaullah Shah

July 5, 2019at 3:28 pmI have corrected the error.

The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.

Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

asdoc with pwcorr currently does not report observations, I shall work on it sometimes in the future.

## Clara

August 14, 2019at 6:05 pmHi,

Thanks for creating and sharing the asdoc command. When I try to use it for spearman results, it produces the results but they are not displayed correctly as it seems to produce the results as individual rows that are stacked together rather than as a single table. See example below. Is there a workaround for this?

Thanks,

## Attaullah Shah

August 18, 2019at 6:09 pmI have added support for spearman command to asdoc.

The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.

Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

Please do remember to cite asdoc. To cite:

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.