pwcorr: pairwise correlations with missing values
Let each correlation use the rows available for that pair, while recognizing that the resulting matrix can combine different analysis samples.
Independent software. Not affiliated with, sponsored by, or endorsed by StataCorp LLC.
Complete example
The example copies read, introduces four missing values into the copy, and then calculates pairwise correlations.
clear
import delimited "data/student_scores.csv"
generate read_gapped = read
replace read_gapped = . if id <= 4
pwcorr math read_gapped write
Output from stats.camp
math read_gapped write
math 1 .986 .9457
read_gapped .986 1 .9801
write .9457 .9801 1
Pairwise deletion changes the sample
The math–read_gapped coefficient uses rows where both variables are present, while the math–writing coefficient uses rows where math and writing are present. Pairwise deletion retains more information than listwise deletion, but the coefficients need not describe one common set of observations.
Missingness can be systematic. A larger pairwise sample is not automatically less biased.
Common options and current limits
- The current implementation produces the symmetric pairwise coefficient matrix.
- Stata's commonly used
sig,obs, andstar()displays add p-values, pair-specific counts, and significance markers. - stats.camp currently accepts
sig,listwise, andcasewise, but does not yet render significance results or apply alternate deletion modes. obs,star(), and multiplicity-adjustment options are not currently part of this command's supported syntax.
The compatibility table therefore marks pwcorr partial. See the current entry and Stata's correlate and pwcorr manual for the broader official behavior.
Related guides
Run this exact example
Clone the example repository in stats.camp and open the exact do-file shown on this page. No stats.camp account is required.
Open this example