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

  • 34

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

Category:asdoc Tags : 

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

Table of contents of asdoc

Generate a correlation table with significance/stars

Generate a table of descriptive statistics

Generate a table of customized descriptive statistics



34 Comments

Zhang Huang

November 12, 2018at 2:48 pm

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

    To download, type
    ssc install asdoc

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

Zhang Huang

November 12, 2018at 2:53 pm

Sorry. It always replies like this in Stata:

ssc install asdoc, replace

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 pm

OK, copy the attached files to the mentioned directories

copy asdoc.ado and asdoc.sthlp to this folder

C:/ado/plus/a

2. Copy the lasdoc.mlib to this folder

C:/ado/plus/l

The last letter is L in small.

Simon

December 25, 2018at 5:44 pm

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

    Simon: The significance stars can be reported using the sub-command pwcorr. For example

    sysuse auto
     asdoc pwcorr price headroom mpg displacement, star(.01) replace

Simon

December 28, 2018at 5:33 pm

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

    Simon: Reporting stars for showing statistical significance at .05 or 0.1 level works the same way as shown above. For example,

    sysuse auto, clear
    * At 5% level
     asdoc pwcorr price headroom mpg displacement, star(.05) replace
    
    * At 10% level
     asdoc pwcorr price headroom mpg displacement, star(.1) replace
    
    				
    				
    				

Anonymous

January 1, 2019at 6:11 pm

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

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

    Philipp
    Thanks 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 pm

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

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

Dear Michael Glencross
The 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 pm

Dear 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

Chris Boulis

April 13, 2019at 1:26 pm

Dr. 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 pm

    Chris Boulis
    It seems you need a wide regression table. In the help file of asdoc, which you can access by typing:

    help asdoc

    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.

    sysuse auto
    asdoc reg price mpg rep78, replace wide
    
    * Add another regression where the dependent variable is trunk
    asdoc reg trunk mpg rep78, wide
    
    * Add third regression where the dependent variable is weight
    asdoc reg weight mpg rep78, wide

    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 am

Dr 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).


Variables                    Life event 1                                    Life event 2                                   Life event 3
                              depvar1       depvar2                   depvar1       depvar2                    depvar1       depvar2
                                0.003             0.004                         0.25               0.21                            0.32              0.28
                                                                                                      
Control vars

Sex                               0.22           0.19                          0.25              0.36                           0.38                0.42
Age                               0.65           0.54                          0.32              0.45                           0.62                0.49                
Emp Status                 etc
Income
Education

Kind regards,
Chris

    Attaullah Shah

    April 14, 2019at 6:23 am

    Chris Boulis
    It 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 pm

Dear 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’.

asdoc xtreg relat b100.time_marr_sep b10.rel b1.age b1.empstat b9.edlev ///

b1.Inc if reli ! = . & wave > = 4 & wave < = 14  & time_marr_sep  96, fe nest replace

 

asdoc xtreg reli b100.time_marr_sep b10.rel b1.age b1.empstat b9.edlev ///

b1.Inc if relat ! = . & wave > = 4 & wave < = 14  & time_marr_sep  96, fe nest append

 

etc.

What do you think?

Kind regards,

Chris

    Attaullah Shah

    April 15, 2019at 6:33 pm

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

    asdoc xtreg relat b100.time_marr_sep b10.rel b1.age b1.empstat b9.edlev ///
    
    b1.Inc if reli ! = . & wave > = 4 & wave < = 14  & time_marr_sep < 104 & ///
    
    time_marr_sep > 96, fe nest replace label
    
     
    
    asdoc xtreg reli b100.time_marr_sep b10.rel b1.age b1.empstat b9.edlev ///
    
    b1.Inc if relat ! = . & wave > = 4 & wave < = 14  & time_marr_sep < 104 & ///
    
    time_marr_sep > 96, fe nest append label

Nighat Seema

April 15, 2019at 8:03 pm

Dear Sir

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

asdoc cor f_con f_con2 f_man exp own_foreign bank_loans audit web exports f_age, label replace

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 pm

    Nighat Seema
    The 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

    asdoc cor f_con f_con2 f_man exp own_foreign bank_loans audit web exports f_age, label replace abb(72)

Anders

June 25, 2019at 1:29 am

Professor,

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 pm

    Anders
    It seems an installation issue. Please install asdoc again by

    ssc install asdoc, replace

    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 pm

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

|Q6_työ~a Q36_vi~n
-------------+------------------
Q6_työ_paha  | 1.0000
Q36_vie_mu~n | 0.0807 1.0000
-------------+------------------
Click to Open File: K:\My Documents/korrelaatiot.doc

But when I call for pwcorr it doesnt work:

asdoc pwcorr Q6_työ_paha Q36_vie_mukanaan , sig star(*0.10 **0.05 ***0.01)  append
invalid varname
r(198);

Could you please help me
Thank you!

    Attaullah Shah

    June 28, 2019at 7:45 pm

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

     asdoc pwcorr Q6_työ_paha Q36_vie_mukanaan , star(all) 

    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 pm

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

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

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

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.

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.

Thomas

July 4, 2019at 9:54 pm

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

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

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

    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.
    asdoc with pwcorr currently does not report observations, I shall work on it sometimes in the future.

Leave a Reply

one × 4 =