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