Announcement

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

  • Rolling forecast after VAR model

    Hello everybody. I am trying to perform rolling window forecast after VAR model with 7 lags. I am able to do both fcast and rolling by itself, but for the third day I am unable to do both together.

    My variables have 558 obs. I would like to roll 1 step prediction 100 times, while keeping first 458 as a basis.

    var variableX variableY if t <= 458, lags(1/7)
    fcast compute p_, step(1)

    This is basicaly what I would like to do 100 times, therefore next step shall be:

    var variableX variableY if t <= 459 & t >= 2, lags(1/7)
    fcast compute p_, step(1)

    Rolling by itself works in this form:

    rolling _b, window(459) clear: var variableX variableY, lags(1/7)

    However, I have no idea, how to connect those two things together, i.e. 100 times subsequently use preceeding 458 observations to estimate the next one. Maybe the easiest thing is to make a program, but I am not able to make it either. Idea of the program cited from stata manual is bellow.

    program myforecast, rclass
    syntax [if]
    regress ibm L.ibm L.spx ‘if’
    // Find last time period of estimation sample and
    // make forecast for period just after that
    summ t if e(sample)
    local last = r(max)
    local fcast = _b[_cons] + _b[L.ibm]*ibm[‘last’] + ///
    _b[L.spx]*spx[‘last’]
    return scalar forecast = ‘fcast’
    // Next period’s actual return
    // Will return missing value for final period
    return scalar actual = ibm[‘last’+1]
    end

    rolling actual=r(actual) forecast=r(forecast), recursive window(20): myforecast


    I am Stata beginner so please, be patient with me. I would be very thankful for any help!
Working...
X