Announcement

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

  • Correlation by group - Presented as a matrix?

    Hi,

    I would like to report correlation between 2 variables in a matrix or any way that would be easy to copy/paste or import in an Excel file. I have a large number of groups so the output I get from Stata is hard to use. Here is the code I have so far:

    Code:
    sysuse auto, clear
    
    sort rep78
    by rep78: pwcorr price weight
    Can someone help me with that? Thanks in advance!

  • #2
    Try this:

    Code:
    clear*
    sysuse auto
    
    capture program drop mycorr
    program define mycorr
        corr price weight
        gen rho = r(rho)
        keep rep78 rho
        keep in 1
        exit
    end
    
    runby mycorr, by(rep78)
    
    list, noobs clean
    Instead of the -list- command at the end, use -export excel- and you're done.

    -runby-, written by Robert Picard and me, is available from SSC.

    Comment

    Working...
    X