Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Export correlation outputs into Word

    Hello,

    I'd like to know what's wrong with sing this correlation command as opposed to the pwcorr (I've read that the latter includes variables with missing obs. too)

    Second, I couldn't manage to export this into my Word, most videos/posts are only showing how to do that with pwcorr. Do I need to switch to pwcorr instead?

    Thank you!

    Code:
    . corr GI RND_L1 LVG EX RER EDU
    (obs=245)
    
                 |       GI   RND_L1      LVG       EX      RER      EDU
    -------------+------------------------------------------------------
              GI |   1.0000
          RND_L1 |   0.4540   1.0000
             LVG |   0.1773   0.0638   1.0000
              EX |   0.3229   0.5012  -0.0861   1.0000
             RER |   0.4979   0.8791   0.0037   0.3009   1.0000
             EDU |   0.3912   0.5412   0.0044   0.1673   0.5892   1.0000

  • #2
    There is nothing wrong with correlate or pwcorr, it all depends on your data analysis requirements and how you want to handle missing values in your data.

    If you have Stata 17 or newer, you can use the new collect commands to get results into a collection, style and arrange the collected results into a table, and publish (export) the table to a Word file.

    See this post for an example using pwcorr and the by prefix to publish pairwise correlations from multiple groups to a single Excel file.

    Here is a simpler example using command correlate with some publicly available data that publishes a table of correlations to a Word file.
    Code:
    webuse nhanes2l
    
    collect corr=vech(r(C)) : ///
        corr vitaminc zinc copper lead
    
    * style choices
    collect style cell result[corr], nformat(%7.4f)
    collect style header result, level(hide)
    
    * default is to show variable labels, but here we set it to show
    * variable names
    collect style header rowname roweq, level(value)
    
    * arrange the correlations
    collect layout (rowname) (roweq#result)
    
    * publish tables to a Word file
    Here are the resulting table.
    Code:
    ------------------------------------------
             | vitaminc    zinc  copper   lead
    ---------+--------------------------------
    vitaminc |   1.0000
    zinc     |  -0.0181  1.0000
    copper   |  -0.0200 -0.1390  1.0000
    lead     |  -0.1692  0.0867 -0.0870 1.0000
    ------------------------------------------
    Here is a screen-shot of the document using LibreOffice on my Mac.

    Click image for larger version

Name:	Screenshot 2024-05-07 at 7.08.17 PM.png
Views:	1
Size:	166.5 KB
ID:	1752628

    Comment

    Working...
    X