I am new to stata and trying to do a (12 month) rolling regression on a dataset including daily returns for shares. Each share ticker has the same number of days of observations and I'm using a while loop to do a regression on a 12 month window for each ticker for each day. This seems to work fine. However, I then need to predict the value for each day for each ticker. The issue I have come across is that you can use the 'by' command to do the regression - for instance:
by ticker, sort : regress daily_return factor_1 factor_2 if inrange(mydate, `i'-`win'+1,`i')
* where `win' is the window size (in business days equivalent to 12 months).
BUT you can not use 'by' option for 'predict' and so using 'predict' following the above command only provides values for the last ticker group.
Any ideas would be much appreciated!
FYI I have also tried using rolling function but this does not like groups with the same ticker name on each observation.
by ticker, sort : regress daily_return factor_1 factor_2 if inrange(mydate, `i'-`win'+1,`i')
* where `win' is the window size (in business days equivalent to 12 months).
BUT you can not use 'by' option for 'predict' and so using 'predict' following the above command only provides values for the last ticker group.
Any ideas would be much appreciated!
FYI I have also tried using rolling function but this does not like groups with the same ticker name on each observation.
Comment