My data are the following:
I have a dataset with 77000 rows and 3 columns.
I want to compute the covariance of dclose and dclose_lag for each identifier ticker2.
So I need 194 covariances.
How can I create a column consisting of the covariances?
I have already computed the variance for the first ticker2, but I can not create a loop.
That is the command i used to compute the covariance for the 1st ticker2:
correlate dclose dclose_lag if ticker2==1, covariance
gen float covname = r(cov_12)

I have a dataset with 77000 rows and 3 columns.
I want to compute the covariance of dclose and dclose_lag for each identifier ticker2.
So I need 194 covariances.
How can I create a column consisting of the covariances?
I have already computed the variance for the first ticker2, but I can not create a loop.
That is the command i used to compute the covariance for the 1st ticker2:
correlate dclose dclose_lag if ticker2==1, covariance
gen float covname = r(cov_12)
Comment