Announcement

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

  • Differences in correlation coefficients produced by corr and reg

    For certain variables, corr and reg produce different correlation coefficients that cannot be explained by rounding error. For example:

    Code:
    webuse lifeexp, clear
    
    * Correlation coefficient from corr (1)
    corr lexp gnppc
    
    * To get the correlation coefficient from reg, first standardize both variables to have mean 0 and standard deviation 1
    egen std_lexp = std(lexp)
    egen std_gnppc = std(gnppc)
    
    * Correlation coefficient from reg (2)
    reg std_lexp std_gnppc
    On Stata 17, (1) is 0.718 and (2) is 0.729.
    Code:
    summarize std_lexp std_gnppc
    and
    Code:
    corr std_lexp std_gnppc
    show that this behavior is not explained by failure of standardization. Both corr and reg use the same observations. What can explain this disparity? It must be something to do with these variables in particular, as for most variables (e.g. those in auto, nlsw88, or this dataset), the correlations produced by corr and reg are almost identical up to rounding error.
    Last edited by Jack Peters; 20 Jul 2022, 14:36.

  • #2
    You are using a different sample to standardize the variables and this little detail matters.

    Code:
    webuse lifeexp, clear 
    
    * Correlation coefficient from corr (1)
    corr lexp gnppc
    
    * To get the correlation coefficient from reg, first standardize both variables to have mean 0 and standard deviation 1
    
    qui reg lexp gnppc
    foreach var in lexp gnppc{
        qui sum `var' if e(sample)
        g std_`var'= (`var'- r(mean))/r(sd) 
    }
    reg std_lexp std_gnppc, nocons
    Res.:

    Code:
    . corr lexp gnppc
    (obs=63)
    
                 |     lexp    gnppc
    -------------+------------------
            lexp |   1.0000
           gnppc |   0.7182   1.0000
    
    
    . reg std_lexp std_gnppc, nocons
    
          Source |       SS           df       MS      Number of obs   =        63
    -------------+----------------------------------   F(1, 62)        =     66.05
           Model |  31.9801064         1  31.9801064   Prob > F        =    0.0000
        Residual |  30.0198953        62   .48419186   R-squared       =    0.5158
    -------------+----------------------------------   Adj R-squared   =    0.5080
           Total |  62.0000017        63   .98412701   Root MSE        =    .69584
    
    ------------------------------------------------------------------------------
        std_lexp |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
       std_gnppc |   .7181979   .0883716     8.13   0.000     .5415455    .8948503
    ------------------------------------------------------------------------------
    Anyway, a quicker way to test your theory is to invoke the -beta- option of regress:

    Code:
    webuse lifeexp, clear 
    
    *Regress -beta-
    regress lexp gnppc, beta
    Res.:

    Code:
    . *Regress -beta-
    
    . 
    . regress lexp gnppc, beta
    
          Source |       SS           df       MS      Number of obs   =        63
    -------------+----------------------------------   F(1, 61)        =     64.98
           Model |  733.446453         1  733.446453   Prob > F        =    0.0000
        Residual |  688.490055        61  11.2867222   R-squared       =    0.5158
    -------------+----------------------------------   Adj R-squared   =    0.5079
           Total |  1421.93651        62  22.9344598   Root MSE        =    3.3596
    
    ------------------------------------------------------------------------------
            lexp |      Coef.   Std. Err.      t    P>|t|                     Beta
    -------------+----------------------------------------------------------------
           gnppc |   .0003234   .0000401     8.06   0.000                 .7181979
           _cons |   69.44836   .5479821   126.73   0.000                        .
    ------------------------------------------------------------------------------

    Comment


    • #3
      Thanks so much!

      Comment

      Working...
      X