Command reference
pwcorr — correlate variables using available pairs
Calculate Pearson correlations while using every available pair of values. Different coefficients can use different observations; request a common sample when you need directly comparable matrices.
Syntax
pwcorr [varlist] [if condition] [in range] [, sig listwise]
Provide at least two numeric variables, or omit varlist to use all numeric variables. if and in restrict the sample before each pair's nonmissing observations are selected. The default is pairwise deletion: a missing third variable does not exclude a row from a correlation between the first two.
Options
Example
The example loads 24 synthetic student records and copies reading scores to read_gapped. It deliberately removes the first four copied scores, then correlates math, the incomplete reading variable, and writing.
clear
import delimited "data/student_scores.csv"
generate read_gapped = read
replace read_gapped = . if id <= 4
pwcorr math read_gapped write
Sample data included. Opens in a new tab; click Run.
What to look for
Math–reading uses 20 pairs, math–writing uses 23, and reading–writing uses 19. The corresponding correlations are approximately 0.9860, 0.9457, and 0.9801. These different sample sizes are the point of the example: each coefficient uses the observations available for its two variables.