Hello everyone on Statalist,

I’m running into an issue regarding forecasting realized volatility using an AR(1) model after the announcement of quarterly earnings by a selection of SP500 companies.

The dataset I have consists of around 100 S&P-500 listed companies with the following variables: Date, Adjusted Closing Price, Earnings (takes value 1 if earnings announcements were done that specific day and zero otherwise) and Returns (simple stock return: D.AdjClose/L.AdjClose). The variables are daily observations over the period 1996 – 2020.

I want to forecast stock returns for the 30 days following the announcement of quarterly earnings using an AR(1) model. The rolling window must be 1000 observations, so the 1000 observations prior to a specific earnings announcement will be used to forecast the stock returns over the 30 days following that announcement.

I am looking for a way to create a code that automatically does the forecasts as described above, but the only way I can see a solution is to do it manually. The code down below is the best I have been able to do so far. The numbers 201, 250 and 50 are just examples to illustrate.

gen AR1_Forecasts = .
forvalues s = 201/250 {
reg Y L.Y if t>=`s'-50 & t<`s'
predict temp if t==`s'
replace AR1_Forecasts = temp if t==`s'
drop temp
}

Any advice is welcome and appreciated.

Thanks in advance,
Stijn Ouwehand