Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: difference b/w corr and pwcorr

 From Maarten Buis <[email protected]> To [email protected] Subject Re: st: difference b/w corr and pwcorr Date Wed, 10 Apr 2013 10:59:17 +0200

On Wed, Apr 10, 2013 at 7:13 AM, Wu Zhang <[email protected]> wrote:
--- On Apr 9, 2013, at 2:56 PM, Wu Zhang wrote:
>>      I wanna know the difference between correlation and pairwise correlation: very confusing, for some varlist, they are the same; while different for other varlist.

The differ with respect to the way they deal with missing values. To
compute a correlation you just need two variables, so if you ask for a
matrix of correlations you could just do so by looking at each pair of
variables separately and inlcude all observations that contain valid
values for that pair. Alternatively, you could say that the entire
list of variables defines your sample, in that case would first remove
all observations that contain a missing value on any of the variables
in the list of variables. -pwcorr- does the former and -corr- does the
latter. In the example below, the variable rep78 is the only variable
with missing values. So -corr- will compute the correlation between
price and trunk on only those observations with valid values on rep78
price and trunk, while -pwcorr- will compute the correlation between
price and trunk on those observations with valid values on price and
trunk. You can use the -if- condition to let -pwcorr- behave like
-corr-.

*------------------ begin example ------------------
sysuse auto

// only rep78 contains missing values
corr rep78 price trunk
pwcorr rep78 price trunk

// reproduce the results from -corr- with -pwcorr-:
pwcorr rep78 price trunk if !missing(rep78, price, trunk)
*------------------- end example -------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/