correlate: Pearson correlations and missing-data checks
Measure linear association among numeric variables while checking which observations actually contribute to each coefficient.
Independent software. Not affiliated with, sponsored by, or endorsed by StataCorp LLC.
Complete example
clear
import delimited "data/student_scores.csv"
correlate math read write
correlate math read if !missing(write)
One writing score is missing. The second command explicitly restricts the math–reading calculation to rows that also have a writing score, providing a practical check on the current deletion behavior.
Output from stats.camp
(obs=23)
math read write
math 1
read .9809 1
write .9457 .9786 1
(obs=23)
math read
math 1
read .9805 1
How to interpret a correlation
The coefficients are all positive and close to one in this invented dataset. The display reports 23 observations because one requested variable is missing. Pearson correlation describes linear association; it does not establish causation or agreement between measures.
Outliers, restricted ranges, nonlinear relationships, and constructed teaching data can all make a coefficient misleading without a plot and subject-matter context.
Common syntax and current limits
corris a supported abbreviation.- An explicit varlist is safer than relying on every numeric variable in the current dataset.
ifandinqualifiers restrict the sample before coefficients are calculated.- The current display reports a listwise observation count, but individual coefficients still use their available pairs. Apply an explicit complete-case qualifier when one common sample is required.
- The official
covarianceoption is commonly used for a covariance matrix. stats.camp currently accepts it but still renders correlations, so the command is marked partial. - Use
pwcorrwhen each pair should use its available observations instead of one common complete-case sample.
See the current correlate entry and Stata's correlate and pwcorr manual for an external reference.
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