Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: difference b/w corr and pwcorr

From   Maarten Buis <>
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 <> 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

*------------------ 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: )

Hope this helps,

Maarten L. Buis
Reichpietschufer 50
10785 Berlin
*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index