correlate: Pearson correlations and missing-data checks

Measure linear association among numeric variables while checking which observations actually contribute to each coefficient.

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

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

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