Dear all,
I have an unbalanced panel dataset of stock and market returns where permno is the panel variable and date is the time variable. The data has been tsset. The sample of interest covers the period from January 1996 through October 2012.
Now I'm trying to estimate 60-months rolling correlations between the stock and market returns. Rolling over 60 months is done by looping. I would like to use the -statsby- command to collect correlation coefficients for the different stocks (permno).
So far, my code looks like this (later I will append all files):
However, tow issues arised when running the code.
1. It takes a lot of time. After 30 minutes, the very first file "corr23953" hasn't been finished, yet.
2. When choosing the "noisily" option, every now and then there is the message
"no observations
captured error running (correlate stock_ret market_ret), posting missing values"
popping up.
My questions are: What did I do wrong? Is there a more efficient way to collect rolling correlations in this case?
Help is highly appreciated.
Best,
Christopher
I have an unbalanced panel dataset of stock and market returns where permno is the panel variable and date is the time variable. The data has been tsset. The sample of interest covers the period from January 1996 through October 2012.
Now I'm trying to estimate 60-months rolling correlations between the stock and market returns. Rolling over 60 months is done by looping. I would like to use the -statsby- command to collect correlation coefficients for the different stocks (permno).
So far, my code looks like this (later I will append all files):
Code:
* 3. Correlations // Daily sample: months from 01Jan1996-31Oct2012 local k = 1996*12+1 // k=Jan1996 local l = 2012*12+10 // l=Oct2012 forvalues i=`k'(1)`l'{ disp `i' quietly use date permno stock_ret market_ret if year(date)*12+month(date)<=`i'&year(date)*12+month(date)>`i'-60 using "C:\...", clear if (r(N)>=200){ quietly statsby rho_s_m = r(rho), by(permno) saving(C:/.../corr`i', replace): corr stock_ret market_ret } }
1. It takes a lot of time. After 30 minutes, the very first file "corr23953" hasn't been finished, yet.
2. When choosing the "noisily" option, every now and then there is the message
"no observations
captured error running (correlate stock_ret market_ret), posting missing values"
popping up.
My questions are: What did I do wrong? Is there a more efficient way to collect rolling correlations in this case?
Help is highly appreciated.
Best,
Christopher
Comment