Announcement

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

  • Pseudo out-of-sample forecast using loops

    Hello, I have tried running a code given to me to predict a pseudo out-of-sample forecast using a loop of autoregression, but I only get syntax error. I suspect I must download an extension or something, but I'm not sure. I would appreciate any help!
    Here's my code:

    local start = tq(2003q1)
    local end = tq(2012q4)

    gen forecast = .

    forvalues i = `start'/`end' {

    * AR(2) regression ;
    reg d_infl L(1/2).d_infl if quarter >= tq(1963q1) & quarter <=`i', robust

    * forecast for the next period ;
    replace forecast = _b[_cons] + _b[L1.d_infl]*L1.d_infl+ _b[L2.d_infl]*L2.d_infl if quarter == `i' + 1 ;
    }

  • #2
    I think the syntax errors are coming from the semi-colons ( ; ) you have placed at the end of some of your commands. In its factory-defaults setting, Stata does not support this. Commands simply end when the carriage return character is encountered. You have the option of issuing the command -#delimit ;-, which will then cause the parser to expect every command to end with a semi-colon. But you cannot have some commands ending with ; and others without it. If you want to use semi-colons you must -#delimit ;-, and you must use the semi-colons consistently at the end of every command (including, for example, things like -forvalues i = `start'/`end' { ; - which, to most people, feels unnatural. If you don't want to use them everywhere, you can't use them anywhere.

    Comment

    Working...
    X