Stata: Correlation and Covariance

Correlation and Covariance

This post will illustrate how to: 1. Create a correlation matrix of variables using the correlate command. 2. Display a correlation matrix as a covariance matrix. 3. Obtain the statistical significance of a correlation using the pwcorr command.

Correlation Matrix

We’ll use the auto dataset for this tutorial.

sysuse auto, clear 

auto

We’ll create a correlation matrix of four variables — price, mpg, weight, and length.

correlation price mpg weight length

corr

Note: We can shorten the correlation command to corr for convenience.

Covariance Matrix

If we want to create of covariance matrix, we simply add the covariance option to the correlation command.

correlation price mpg weigh length, covariance

covariance

Statistical Significance of a Correlation

The 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 sig option.

pwcorr price mpg weight length, sig

pwcorr

Comment are closed.