Skip to main content
v2026.11,772 entries · CC-BY 4.0

Correlation Matrices in Stata: correlate vs. pwcorr

Stata’s correlate and pwcorr both build a correlation matrix, but correlate uses listwise deletion and pwcorr uses pairwise deletion by default — here is how to choose, match the two, and export the result.

Ask CASRAI · included with Regulatory Radar

Ask about Correlation Matrices in Stata: correlate vs. pwcorr

Ask CASRAI answers research-administration questions about this guide and cites the passages behind every claim — and says so when the corpus does not cover something, instead of guessing. It comes with a Regulatory Radar subscription at $29 a month, alongside the daily digest of regulatory changes and the dashboard of what changed.

150 questions a day, on this site, over the API, or inside your own tools through the CASRAI MCP server.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Written and maintained by CASRAI Editorial Board

Last updated

Stata has two commands for a correlation matrix, and they do not treat missing data the same way. correlate uses listwise (casewise) deletion: an observation is dropped from the whole matrix if it is missing on any variable in the list, so every pairwise correlation is computed on the identical set of observations. pwcorr uses pairwise deletion by default: each cell of the matrix uses every observation that has non-missing data for that specific pair, so different cells can be based on different sample sizes. Neither behavior is a bug in the other command — they are two different, defensible ways to handle missing data, and the right choice depends on how much missingness the dataset actually has and whether it is scattered across variables or concentrated in a few.

correlate: syntax and listwise deletion

The basic syntax is correlate varlist, e.g. correlate age income education satisfaction. Stata computes the full matrix using only the observations that have non-missing values on all four variables. If age is missing for 40 respondents and income is missing for a different 30, both sets of respondents drop out of every cell of the matrix, not just the cells involving the variable that is actually missing for them. correlate has no built-in significance-star or p-value option — it reports only the coefficients. Add the covariance option to see the covariance matrix instead of correlations, and means to print variable means, standard deviations, and observation counts alongside it.

pwcorr: syntax and pairwise deletion

The basic syntax is pwcorr varlist. Where correlate stays silent on significance, pwcorr is built for reporting it:

  • pwcorr varlist, sig prints the two-sided p-value under each correlation coefficient.
  • pwcorr varlist, star(.05) flags coefficients significant at the 5% level with an asterisk (use star(.01), star(.001), etc. for a stricter cutoff).
  • pwcorr varlist, obs prints the number of observations behind each individual cell — worth turning on any time missingness is uneven, since it is the only way to see that the N differs cell to cell.
  • pwcorr varlist, print(.05) suppresses coefficients that are not significant at the stated level, useful for scanning a large matrix.
  • pwcorr varlist, bonferroni or pwcorr varlist, sidak adjust the significance levels for the number of pairwise comparisons in the matrix, the same multiple-comparisons logic used elsewhere in Stata (see the guide on Tukey’s HSD for the same idea applied to group comparisons rather than correlations).

These options combine freely, e.g. pwcorr age income education satisfaction, sig star(.05) obs gives coefficients, p-values, significance stars, and per-cell observation counts in one table.

Making pwcorr match correlate’s deletion rule

The two commands are not a permanent fork in how missing data gets handled. pwcorr accepts a listwise option (also written casewise) that switches it to the same casewise deletion correlate uses by default: pwcorr varlist, listwise sig star(.05) gives a matrix with correlate‘s sample composition but pwcorr‘s significance reporting. This is the practical reason most Stata users default to pwcorr even when they ultimately want listwise deletion — it is a strict superset of what correlate can do, not a different tool.

Which deletion rule to use

Pairwise deletion (the pwcorr default) keeps more data in each individual cell, which can matter when a variable list is long and missingness is scattered thinly across many variables — dropping a case for every variable it is missing on anywhere in the list can shrink an already-small sample fast. The tradeoff is that the resulting matrix is not internally consistent: it was not generated from one single dataset, so results computed from it downstream (e.g. feeding the matrix into a factor analysis or SEM by hand) can behave oddly, and in the worst case a pairwise-deleted correlation matrix is not guaranteed to be positive semi-definite. Listwise deletion (correlate, or pwcorr, listwise) guarantees internal consistency at the cost of a smaller, identical N across every cell. As a working rule: use listwise deletion when the matrix itself is an input to something else (factor analysis, SEM, computing a composite scale), and pairwise deletion is defensible as a first descriptive look when missingness is low and you are reporting the matrix on its own. If missingness is substantial either way, treat it as a data problem to solve directly — CASRAI’s guide on multiple imputation covers the standard alternative to picking a deletion rule at all.

Exporting the matrix

None of the built-in display commands write directly to Word or Excel; three real routes handle it:

  • estpost + esttab (from the community-contributed estout package, ssc install estout): estpost correlate age income education satisfaction, matrix listwise followed by esttab using correlations.csv, replace unstack not noobs compress b(2) nonote label produces a clean, publication-style CSV or RTF table. The unstack option lays the matrix out in the familiar square, wide format rather than esttab’s default long list.
  • asdoc (community-contributed, ssc install asdoc): prefixing the correlation command, e.g. asdoc pwcorr age income education satisfaction, star(.05), sends the output straight to a Word (or Excel/LaTeX/HTML) file with journal-style formatting, no separate export step.
  • outreg2 (community-contributed, ssc install outreg2): works after estpost the same way it exports regression tables, and is a reasonable choice if a project’s other tables are already using it, for consistency.

For a quick one-off, copying the results-window output directly into Word or Excel still works and is often faster than installing a package for a single table that will not be reused.

A worked example

Suppose a dataset has age, income, and two survey scales, satisfaction and engagement, and income is missing for roughly 15% of respondents while the other three variables are fully observed:

. correlate age income satisfaction engagement
(obs=850)

. pwcorr age income satisfaction engagement, sig star(.05) obs

correlate reports one N (850) for the whole matrix — every cell, including age-satisfaction, which has no missing data on either variable, is computed on the same reduced 850 observations because income‘s missingness removed those rows from the entire matrix. pwcorr with obs would show the age-satisfaction cell computed on the full 1,000 observations while the income-involving cells stay at 850 — the same underlying data, two different bookkeeping choices about what counts as “the sample” for each number in the table.

Related CASRAI guides

For interpreting what the coefficients themselves mean once you have the matrix, see How to Read a Correlation Matrix. For a correlation coefficient between two binary variables specifically, see the phi coefficient; for two categorical variables more generally, see Cramer’s V. If the variables in the matrix will feed into a regression model next, Regression in Stata and robust standard errors cover what changes once correlated predictors go into that model. For the broader question of Stata versus other statistical software for this kind of work, see SPSS vs. Stata for Statistical Analysis. For structuring the do-file this analysis lives in, see Stata do-files: structure and reproducible workflow.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Regulatory Radar

Stop finding out after the fact

$29/month, cancel anytime. Daily digest updates from our analysis, a dashboard holding the same items, and a cited assistant for everything they raise.

  • Federal Register, Federal Register+, Grants.gov, Regulations.gov, NSF News, UKRI, plus CASRAI’s own published content.
  • 44,322 indexed passages, and every answer cites the ones it drew on.