Correlation

correlate

correlate and pwcorr both calculate correlations. But correlate calculates correlations where all cases included are nonmissing; if one case has missing observation, the entire row is removed from calculation.

. sysuse auto
. corr rep78 mpg price

calculates pairwise correlations among the three variables. rep78 contains missing values; so when calculating the correlation of mpg and price, it only includes the observations where values of rep78 are nonmissing.


(obs=69)
   
             |    rep78      mpg    price
-------------+---------------------------
       rep78 |   1.0000
         mpg |   0.4023   1.0000
       price |   0.0066  -0.4559   1.0000      
      	

pwcorr

. pwcorr rep78 mpg price if !missing(rep78, mpg, price) does the same thing as above.


   
             |    rep78      mpg    price
-------------+---------------------------
       rep78 |   1.0000
         mpg |   0.4023   1.0000
       price |   0.0066  -0.4559   1.0000      
      	
However, pwcorr rep78 mpg price, without if !missing(rep78, mpg, price), would include the observations where rep78 has missing values when calculating the correlation of mpg with price.

             |    rep78      mpg    price
-------------+---------------------------
       rep78 |   1.0000 
         mpg |   0.4023   1.0000 
       price |   0.0066  -0.4686   1.0000 
     		

Author: Yun Dai, 2018