Stata: Correlation and Covariance
Correlation and Covariance
This post will illustrate how to:
1. Create a correlation matrix of variables using the
2. Display a correlation matrix as a covariance matrix.
3. Obtain the statistical significance of a correlation using the
We’ll use the auto dataset for this tutorial.
sysuse auto, clear
We’ll create a correlation matrix of four variables — price, mpg, weight, and length.
correlation price mpg weight length
Note: We can shorten the
correlation command to
corr for convenience.
If we want to create of covariance matrix, we simply add the
covariance option to the
correlation price mpg weigh length, covariance
Statistical Significance of a Correlation
correlation command produces a clean correlation matrix (or covariance matrix with the
covariance option). If we want to see the statistical significance of a correlation, we need to use the
pwcorr command with the
pwcorr price mpg weight length, sig