Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Recursive out-of-sample forecasting

    Hi,

    I have a dataset containing panel data for the period 2008-2015. I want to use recursive forecasting to create predictions on an out-of-sample basis. The main idea is as follows:

    I want to estimate a simple regression model (y on x1 and x2) for year=2008 and use the estimated model to predict the y value for 2009 -->> estimate the regression model for year=2008 +2009 and use the estimated model to predict the y value for 2010 -->> etc. Repeat this process until I have obtained predicted values for my y variable for the years 2009-2015.

    Is there an efficient way to do this which also allows me to store the predicted values under one variable name (y_pred)?

    Many thanks, Ali

  • #2
    I don't have any ideas on the broader issues, but with regard to

    store the predicted values under one variable name (y_pred)
    I think you will find it most straightforward to adopt an approach like the following, which creates the predictions in an intermediate variable and copies the values for the desired year into the desired variable.
    Code:
    generate y_pred = .
    forvalues yr=2008/2015 {
        regress y x1 x2 in 2008/`yr'
        local yrp = `yr' + 1
        predict prdn if yr==`yrp'
        replace y_pred = prdn if yr==`yrp'
        drop prdn
    }

    Comment

    Working...
    X