Pearson Correlation in Stata
Missing Data, p-Values and the Absent Interval
Pearson correlation in Stata comes from two commands that treat missing values differently, so one set of variables can return two tables. Neither prints an interval for r, so one is built from the stored results with the Fisher z transformation.
IN SHORT
What correlate and pwcorr Return, and What They Omit
A Pearson correlation estimates the strength and direction of the straight-line association between two continuous variables, and it is read with a scatterplot and an interval. To run a Pearson correlation in Stata, type correlate followed by the variable list for a matrix built from complete cases, or pwcorr with the obs and sig options for the coefficient, the sample size and the p-value of each pair. The two commands can disagree when values are missing, because correlate drops a row if any listed variable is absent and pwcorr works pair by pair. OnlineSPSS, a specialist statistical consultancy for academic, clinical and professional research, carries out and reviews this analysis through an in-house PhD-level statistician.
In This Guide
ANALYSIS SUPPORT
Analysis Support for This Method
A coefficient describes association and nothing more. When the question is how much one variable changes with another, a regression gives the slope and its interval directly.
Correlation Analysis (Pearson & Spearman)
Linear and rank-based association between variables, with intervals, the sample behind every coefficient and the scatterplot that supports the choice of coefficient.
Simple Linear Regression
One outcome predicted from one variable, with the slope in the outcome's units, its interval and the residual checks that stand behind the fitted line.
BEFORE YOU RUN IT
What Both Commands Take From the Data
Each point below names a property of the data that changes what a cell of the matrix means, and none of them is visible in the output of either command.
Continuous, Roughly Linear Pairs Pearson's r summarizes a straight-line pattern. A curve or a few extreme points can give an r that misdescribes the data, so each pair is plotted before any coefficient is trusted.
A Rule for Missing Values With gaps in the data, correlate keeps complete cases and pwcorr uses every pair it can. Choosing between them fixes the number of rows behind each coefficient in the table.
Independent Observations The p-value assumes each row is a separate participant. Repeated measures on the same people or participants nested in groups usually make it too small, and another model is needed.
A Range Worth Noting A sample drawn from a narrow slice of a scale usually shrinks r. The range of each variable is checked, so a modest coefficient is not read as a weak relationship in the wider population.
IN STATA
How to Run a Pearson Correlation in Stata
Both commands ship with official Stata, so the matrix, the pairwise table and the p-values need no add-on, while the interval is computed from stored results.
Plot Each Pair Before Testing
Draw a scatterplot of every pair of interest and look for curvature, outliers and a narrow range before any coefficient is computed.
Watch: In a small sample, one extreme point can create or erase a correlation. Note any such point, and report the coefficient without it only as a labeled sensitivity check.
Run correlate for Complete Cases
Type correlate with the variable list. Stata drops every row with a missing value on any listed variable before computing any coefficient.
Check: correlate prints (obs=N) above the matrix. Compare that N with the number of rows in the file, because a large gap means missing values are shaping the sample.
Run pwcorr With obs and sig
Run pwcorr with the obs and sig options to see the coefficient, the sample size and the p-value for each pair.
Tip: With many coefficients on display, bonferroni or sidak adjusts the printed significance levels. State how many pairs were examined, whether or not an adjustment is used.
Compare the Two Samples
Add listwise to pwcorr, or set the two tables side by side, and see which pairs lose rows when the complete-case rule applies.
Check: When the two tables differ, the missing values are not trivial. The methods name the rule used, since each coefficient then refers to different participants under each rule.
Add the Fisher z Interval
After a two-variable correlate, take r and n from the stored results, transform r with atanh, add and subtract the margin, and return with tanh.
Watch: The interval is an approximation that assumes roughly bivariate normal data. With a small n or a strongly skewed pair it is less trustworthy, and a rank-based coefficient may suit better.
Save the Commands and Log
Keep the commands in a do-file and open a log, so the matrix, its sample and the interval can be reproduced together.
Tip: Put the n used for each interval in a comment beside its command. A reader asking which rows entered a coefficient then finds the answer in the file itself.
twoway scatter y x
correlate y x z
pwcorr y x z, obs sig
correlate y x
display tanh(atanh(r(rho)) - invnormal(.975)/sqrt(r(N) - 3))
display tanh(atanh(r(rho)) + invnormal(.975)/sqrt(r(N) - 3))
READING THE OUTPUT
Reading the Matrices That correlate and pwcorr Print
The two layouts look alike, but the sample behind each cell differs, so the rows under the coefficient matter as much as the coefficient.
| Output element | What it tells you | What to check |
|---|---|---|
| (obs=N) above the correlate matrix | Complete cases used for every coefficient | That N matches the sample intended after listwise deletion |
| Cell in the correlate matrix | r for the pair, from complete cases only | That the value is read beside the scatterplot of the pair |
| Cell in the pwcorr matrix | r for the pair, from all rows holding both values | That the rows behind each cell are those the obs option lists |
| obs row under a coefficient | Rows that entered that pair | That a pair with few rows is not read like the others |
| sig row under a coefficient | Two-sided p-value for a correlation of zero | That it is read as evidence against zero, not as the size of r |
| Asterisk from star() | Marks p-values at or below the chosen cutoff | That the cutoff and any adjustment are stated |
| Diagonal of 1.0000 | Each variable correlated with itself | That it is left out of any table in the manuscript |
| Computed Fisher z limits | Range of correlations compatible with the data | That the transformation and the n used are named |
REPORTING
Reporting a Pearson Correlation From Stata Output
A correlation sentence is short, so each missing detail, from the deletion rule to the interval, stands out to a reader.
Give the coefficient with its degrees of freedom and interval, r(df) = ___, 95% CI [___, ___], p = ___, where df is the number of pairs used minus 2. Take n from the (obs=) line of correlate or from the obs option of pwcorr, and say which command produced it, since correlate keeps complete cases and pwcorr keeps every available pair. In a matrix table, put the deletion rule in a note and give the n of each pair when it varies. Describe direction and size in words at the scale of the variables, and add the scatterplot when the form of the association matters. State how many coefficients were examined, because p-values from a large matrix are not read one at a time, and describe the result as an association, not an effect. When listwise deletion was used, give the single n of the whole matrix.
COMMON MISTAKES
Correlation Tables Taken at Face Value
The matrix looks finished the moment it prints, yet each point below changes what one of its cells means.
Two Commands, One Sample Assumed A table from pwcorr and one from correlate are compared as if they described the same participants. With missing values they do not, and the n differs from pair to pair.
Interval Left Out Neither command prints a confidence interval, so a table of r and p alone leaves the precision unreported. The Fisher z interval is added, with the n behind it stated.
Significance Read as Size In a large sample a small p-value can sit beside a weak coefficient. The size of r, judged in context, answers how strong the association is, and the p-value does not.
Pairwise n Not Reported A matrix whose pairs rest on different numbers of rows needs those numbers shown, perhaps in a second table. Otherwise a reader cannot tell which coefficients are well supported.
A Curve Summarized by r A U-shaped or leveling-off pattern can return an r near zero while the variables are strongly related. Without the scatterplot the coefficient is misread.
Pattern Read as Cause A coefficient alone does not show that one variable drives the other. Wording that implies an effect needs a design, or an argument about confounding, that supports it.
Matrix printed but the sample behind it unclear? Independent Statistical Review matches each coefficient with the rows and the deletion rule that produced it.
FREQUENTLY ASKED QUESTIONS
Questions About Missing Values and Intervals in Stata Correlations
Stata hands the researcher two tables that can disagree and no interval for r, and both gaps can be closed with commands already installed.
Correlate versus pwcorr: why do the coefficients differ?
correlate drops a row if any listed variable is missing, while pwcorr uses every row that holds both values of a pair. With complete data the two agree. With gaps, each pwcorr cell can rest on its own sample, and the obs option shows how large each one is. Adding listwise to pwcorr applies the rule of correlate.
Does Stata print a confidence interval for r?
Not with correlate or pwcorr, which print the coefficient and, when sig is given, the p-value. The interval is built from the Fisher z transformation of r and the number of pairs, and it can be programmed in a few lines from the stored results. State the method used, and treat it as approximate in small samples.
Can pwcorr in Stata mark which coefficients are significant?
Yes: star(.05) marks coefficients with a p-value at or below the cutoff, and print(.05) hides the others. Both work from the displayed significance level, so bonferroni or sidak changes what is starred. A starred matrix shows association, not its size, so the coefficients and sample sizes stay in the table.
Which rows, pairs and intervals does a check of my table cover?
An in-house PhD-level statistician at OnlineSPSS compares your correlate and pwcorr output with the rows in your file, adds the interval and prepares the note on deletion. The stage belongs to Results Reporting & Interpretation, and what the associations mean in your field remains yours.
How do you protect my research data and confidentiality?
Your data and project details are handled confidentially, and project information is not published. Researcher names and institutions are not used publicly without permission. An NDA is available where required and can be arranged before sensitive materials are shared. Read more about confidentiality and data security.
What happens when I request an assessment, and how long does it take?
You share your research question, design and relevant materials, such as the dataset or the output you have, and a statistically trained Research Coordinator reviews the request and responds the same day. The analysis, deliverables, timeline and one fixed project fee are then confirmed before any work begins, so the timeline follows from the agreed scope.
Still have a question? Find more answers in our full FAQ.
NEXT STEP
Which Rows Sit
Behind Each Coefficient?
A reader tracing a coefficient looks for the deletion rule, the n per pair and the interval. The assessment is where the scope for adding whatever is missing gets agreed.
No Commitment Required
Strictly Confidential
Fixed Project Fee
In-House PhD-Level Statisticians
Same-Day Response
Serving Researchers Since 2014