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, sigprints the two-sided p-value under each correlation coefficient.pwcorr varlist, star(.05)flags coefficients significant at the 5% level with an asterisk (usestar(.01),star(.001), etc. for a stricter cutoff).pwcorr varlist, obsprints 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, bonferroniorpwcorr varlist, sidakadjust 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
estoutpackage,ssc install estout):estpost correlate age income education satisfaction, matrix listwisefollowed byesttab using correlations.csv, replace unstack not noobs compress b(2) nonote labelproduces a clean, publication-style CSV or RTF table. Theunstackoption 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 afterestpostthe 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.








