Differences between revisions 2 and 3
Revision 2 as of 2025-10-06 19:31:10
Size: 899
Comment: Style fix
Revision 3 as of 2025-10-24 16:53:15
Size: 852
Comment: Rewrite
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
The '''`correlate`''' command calculates [[Statistics/Covariance|correlations]]. '''`-correlate-`''' calculates [[Statistics/Correlation|correlations]].

See also [[Stata/PwCorr|-pwcorr-]].
Line 13: Line 15:
To calculate the correlation matrix for some varlist, try: To calculate the [[Statistics/Correlation|correlation]] matrix for some varlist, try:
Line 20: Line 22:
To calculate the covariance matrix, try: To calculate the [[Statistics/Covariance#Matrix|covariance matrix]], try:
Line 33: Line 35:
Note that this command does not support weighting, as it is not an estimation command. To calculate the covariance matrix of [[Stata/Svy|survey estimates]], for example, try using [[Stata/Proportion|proportion]]: Note that this command does not support [[Stata/Weights|weights]], as it is not an estimation command.
Line 35: Line 37:
{{{
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
}}}
----



== See also ==

[[https://www.stata.com/manuals/rcorrelate.pdf|Stata manual for -correlate-]]

Stata Correlate

-correlate- calculates correlations.

See also -pwcorr-.


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 weights, as it is not an estimation command.


See also

Stata manual for -correlate-


CategoryRicottone

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