I am working with time series data and fitting an autoregressive model using OLS. For reference, here is my price data for the commodity (I am not sure how to better format data for this site):
15.6 16.25 16.25 16.25 18.1 18.25 17.9 17.65 17.5 17 17.8 18 18 18.05 18.25 16.25 17.87 18.25 17.9 18.25 18.25 18.25 18.25 18.25 18 18.06 18.25 18.25 18.25 18.37 18.5 18.25 18.25 18.25 18.25 18.25 18.25 18.25 18 17.5 17.5 17.3 17.5 16.8 16.22 16.25 19 22.5 22.5 22.69 23.62 26.75 27.5 26.9 24.25 21.1 19.44 18.5 18.35 18.12 17.02 16.75 16.63 16.63 16.63 16.63 16.65 16.93 18.12 20 21 23 23.25 22.44 22.13 21.9 21.5 21.5 20.75 20.75 20.5 20.2 20 20 19.87 19.25 19 19 19 19 19 19 19 19 19 19 18.81 18.75 18.31 18 18 18.66 18.94 19.68 20.6 21.87 21.25 21.49 21.69 21.5 21.63 22.13 22.25 24.33 25.25 24.5 23 21.75 20.75 20.75 20.75 20.75 20.75 20.75 20.75 20.75 20.75 20.75 19.75 18.25 16.5 16 14.5 14.5 11.5 11.5 11.75 12.5 11.75 12.13 11.5 14.25 14.25 14.25 14.08 14 14 13.25 12.75 12.75 12.75 12.75 12.75 12.75 12.75 12.75 13.75 13 14.25 15 16 16.5 19 21 22.25 24.25 24.5 25 25 25 25.5 27 25 25 20 18 16.5 16 15 15 15 15 15.5 15 15 15 16 16.5 18 20 21 24 23 22 22 22 22 22.5 23 24 25.5 25.5 25.75 25.75 25.75 25.75 25.75 26.25 26.25 26.25 26.25 26.25 26.75 26.75 27.25 27.25 27.25 28 28.25 31.25 39.88 43.75 46.15 47 48.05 48.75 48.75 48.75 49.125 49.5 50.25 52.125 52.25 52.25 49.75 47.5 46.08333333 43.5625 41.8125 41.25 40 36.5625 37.5 34.625 32.13 31 30.63 30.5 31.06 34.5 36.33 37.06 38.5 39 40 40 40 40 39.5 38.85 38.75 37.8125 37.25 36.875 35.13 34.75 34.75 34.25 34.15 34.25 34.25 34.5 34.5 34.9 34.91 34.79 33.94 33.5 33 32.95 32.75 32.75 32.75 32.5 31.94 31.75 31.75 31.75 37
However, this question applies to any data set. I am currently working in STATA, but have seen from a coleague that his R code to predict future prices is:
fit=ar.ols(lg, aic=F, order.max=3,demean=F, intercept=T) fore = predict(fit, n.ahead=12)
Predicting 12 periods ahead, he obtains the following results:
>[1] 39.10485 40.71541 41.58133 42.04069 42.20034 42.16457 41.99738 41.74455 >[9] 41.43697 41.09589 40.73577 40.36645
I have seen this similar question posed, however, no clear answer, or answers given do not work for me: when I predict future periods, I only obtain results for one period ahead.
For example:
tsappend, add(12) g lag1 = lg[_n-1] g lag2 = lg[_n-2] g lag3 = lg[_n-3] reg lg L1.lg L2.lg L3.lg predict xb, xb
Note, I created my own lags because someone postulated that predict was not working well with the lag operator L. However, the only prediction I get back is:
39.10485
which is in fact the same as the R result. However, no matter what I try I cannot obtain more than a single prediction. I have also tried using STATA's forecast, which gave me the same and single forecasted number.
How can I obtain the forecasted models for more than a single period in STATA?
Best Answer
First, reg
may not be the best option for regressing a time series, since they will tend to be autocorrelated. In Stata, you have quite a few options to deal with this, including prais
, and arima
.
Try arima
,
arima lg L1.lg L2.lg L3.lg
Make sure you have 12 rows at the end of your data with a blank lg
, which you want to predict. Then look at predict arima
, specifically the dyn
option. You are wanting a dynamic prediction (where prior predictions are carried forward as lagged independent values) rather than a non-dynamic prediction where you specify the independent variables a priori. If you were using non-lagged independent variables, you'd obviously have to have values for them in the 12 rows.