Differences between revisions 1 and 2
Revision 1 as of 2025-10-06 19:30:10
Size: 898
Comment: Initial commit
Revision 2 as of 2025-10-06 19:31:10
Size: 899
Comment: Style fix
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Stata Correlate= = Stata Correlate =

Stata Correlate

The correlate command calculates correlations.


Usage

To calculate the correlation matrix for some varlist, try:

corr varlist
matrix cor = r(C)

To calculate the covariance matrix, try:

corr varlist, covariance
matrix cov = r(C)

To calculate the precision matrix, follow-up the above with:

matrix invcov = invsym(cov)  //note that invsym() is preferred over inv()

Note that this command does not support weighting, as it is not an estimation command. To calculate the covariance matrix of survey estimates, for example, try using proportion:

svy: prop A B C D
estat vce
mata: st_matrix("cov", st_matrix("e(V)")[(1,3,5,7), (1,3,5,7)]) // select only every other row


CategoryRicottone

Stata/Correlate (last edited 2025-10-24 16:53:15 by DominicRicottone)