Hi everyone,

I am trying to create a variable [pre], the value of which will be the correlation of two other variables [price_return and equal_weighted_return].

I tried using egen, but it generated a lot of missing values even though both the variables had values applicable. My codes were the following:


sort fiscalyear

egen pred2=corr( price_return equalweightedreturnincldivi), by(fiscalyear)
(55442 missing values generated)

I am working with a panel dataset, however if i sort the data using two identifiers [company_id and fiscalyear], I am getting more missing values.


Any suggestions to solve this easy problem?