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.

Tested 2026-08-06 with the current stats.camp development build · View the do-file on GitHub

Open this example View supported commands

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