Dear Statalist,
I would like to ask a question about the forecast command when using panel data. I have read the official documentation but unfortunately cannot figure out what is causing my problem.
I have a strongly balanced panel and would like to make forecasts into the future. In order to evaluate the "quality" of these forecasts, I would like to estimate my model on a subset of the observations, compute the dynamic forecasts (for let's say 5 periods into the future) and then compare my forecasts to the actual values available in my dataset. Keeping only 1 variable (y) and 5 panels with 20 periods each, this is what my data may look like.
I will keep the model as simple as possible just to highlight the main point. The problem is that the static and dynamic forecasts produced by stata are exactly the same; after some investigation I realized they are exactly the same as the predicted values of my model.
It makes completely sense to me that the predicted values from the model and the static forecasts coincide, as the static forecasts correctly use the actual value of the lagged variable when producing the prediction for the next period (which is equivalent to computing a predicted value in my simple model). What is puzzling me is that the dynamic forecasts are apparently computed the same way, whereas I would have expected Stata to use the forecasted values to compute the next period forecast. In my opinion, the dynamic and static predictions should coincide only in the 1st period of the forecasting horizon; then starting from the second period, they should begin to be different (unless the model's predictions are perfect).
The only way I can achieve what I expect is to manually replace the true values of my y variable over the forecasting horizon with the forecasted values. In this way I am "forcing" Stata to use the forecasted values in place of the actual ones when it computes the forecasts. This time the forecasts differ from the predicted values (as expected), but the dynamic and static forecasts are still the same.
To sum up, it seems that the default option for Stata is a static forecast, regardless of whether the user specifies the static option or not. Is it possible that the forecast command is not properly working with panel data when asked to produce dynamic forecasts? Am I missing something?
Any kind of support would be very much appreciated. Many thanks in advance!
I would like to ask a question about the forecast command when using panel data. I have read the official documentation but unfortunately cannot figure out what is causing my problem.
I have a strongly balanced panel and would like to make forecasts into the future. In order to evaluate the "quality" of these forecasts, I would like to estimate my model on a subset of the observations, compute the dynamic forecasts (for let's say 5 periods into the future) and then compare my forecasts to the actual values available in my dataset. Keeping only 1 variable (y) and 5 panels with 20 periods each, this is what my data may look like.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long ID float date long y 1 21561 938 1 21562 2061 1 21563 0 1 21564 851 1 21565 564 1 21566 630 1 21567 564 1 21568 1188 1 21569 1868 1 21570 0 1 21571 702 1 21572 589 1 21573 626 1 21574 589 1 21575 1020 1 21576 1492 1 21577 0 1 21578 860 1 21579 526 1 21580 533 3 21561 42 3 21562 73 3 21563 0 3 21564 4 3 21565 44 3 21566 16 3 21567 158 3 21568 51 3 21569 123 3 21570 0 3 21571 5 3 21572 23 3 21573 6 3 21574 96 3 21575 62 3 21576 86 3 21577 0 3 21578 12 3 21579 78 3 21580 25 4 21561 1609 4 21562 2171 4 21563 36 4 21564 753 4 21565 826 4 21566 673 4 21567 897 4 21568 1747 4 21569 2683 4 21570 28 4 21571 703 4 21572 581 4 21573 814 4 21574 1067 4 21575 1872 4 21576 2586 4 21577 18 4 21578 786 4 21579 612 4 21580 644 7 21561 237 7 21562 306 7 21563 0 7 21564 271 7 21565 218 7 21566 263 7 21567 254 7 21568 239 7 21569 293 7 21570 0 7 21571 832 7 21572 331 7 21573 298 7 21574 316 7 21575 159 7 21576 182 7 21577 0 7 21578 293 7 21579 329 7 21580 278 8 21561 1676 8 21562 1933 8 21563 284 8 21564 1455 8 21565 1367 8 21566 1517 8 21567 1592 8 21568 2382 8 21569 2515 8 21570 522 8 21571 1939 8 21572 1595 8 21573 1385 8 21574 1670 8 21575 2524 8 21576 2611 8 21577 361 8 21578 1701 8 21579 1659 8 21580 1782 end format %tdnn/dd/CCYY date
Code:
xtset ID date qui: xtreg y l1.y if date <= td(26/1/2019), fe predict autoreg_fe_hat, xb estimates store tot forecast create autoreg_fe_model, replace forecast estimates tot, name(autoreg_fe_y, replace) forecast solve, begin(td(27/1/2019)) end(td(31/1/2019)) static prefix(static_) forecast solve, begin(td(27/1/2019)) end(td(31/1/2019)) prefix(dynamic_) estimates clear browse ID date autoreg_fe_hat static_autoreg_fe_y dynamic_autoreg_fe_y if date >= td(27/1/2019)
The only way I can achieve what I expect is to manually replace the true values of my y variable over the forecasting horizon with the forecasted values. In this way I am "forcing" Stata to use the forecasted values in place of the actual ones when it computes the forecasts. This time the forecasts differ from the predicted values (as expected), but the dynamic and static forecasts are still the same.
Code:
drop static_autoreg_fe_y dynamic_autoreg_fe_y replace y = autoreg_fe_hat if date == td(27/1/2019) qui: xtreg y l1.y if date <= td(26/1/2019), fe replace y = _b[_cons] + _b[l1.y]*y[_n-1] if date > td(27/1/2019) & date <= td(31/1/2019) forecast solve, begin(td(27/1/2019)) end(td(31/1/2019)) static prefix(static_) forecast solve, begin(td(27/1/2019)) end(td(31/1/2019)) prefix(dynamic_) browse ID date autoreg_fe_hat static_autoreg_fe_y dynamic_autoreg_fe_y if date >= td(27/1/2019)
Any kind of support would be very much appreciated. Many thanks in advance!
Comment