Announcement

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

  • Forecast vs Predict functions in Stata

    Hi Statalist geniuses,

    I am quite new to Stata and I am trying to understand the difference between Stata's forecast and predict functions.
    I tried to read the methods part in the manual to see what each of them does, but I don't really understand it.
    Basically what I am trying to do is generate out of sample forecasts of investment based on lags of GDP Tobin's Q and an uncertainty variable.

    I want to do recursive estimation for 12 quarters.

    What I have been doing is this:

    Code:
     reg I L(1/4).GDP L(0/4).Q L(0/4).UNC, robust]
    estimates store Spec1
    forecast create spec1forecast, replace
    forecast estimates spec1
    forecast solve, prefix(f_) begin(tq(2016q3)) end(tq(2019q1))

    Does that provde me with dynamic forecasts, based on recursive rather than rolling window?
    Or would I use predict and somehow create a loop?

    I'm sorry if this is a really stupid question, I've been trying to figure this out for a day and I've become kinda blind.

    Thanks so much for your help!
    Last edited by Anja Heimann; 09 Jul 2019, 11:32.

  • #2
    You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

    Forecast is much more flexible than predict. Forecast does a pile of things. However, I don't think you have a dynamic model (since I only appears as the dv), so you're probably not getting a dynamic forecast. Have you run both and looked at what you get?

    Comment


    • #3
      Hi Phil,
      thank you for your reply.
      I forgot to write L(0/4).I after regress when I posted this, so I do have a dynamic model.
      I thought that I couldn't use predict because it doesn't update, i.e. it only makes one step ahead forecasts?
      I tried to write a loop like that ibm example in the stata manual and also like some people have done here on the forum, but I can't get it to work:
      Sorry, this looks pretty messy:

      Code:
      [program myforecaset, rclass
      syntax [if]
      regress L(0/4).DlnI L(1/4).DlnGDP L(0/4).UCCd `if', robust
      summ tq if e(sample)
      local last=r(max)
      local fcast=_b[cons]+_b[L1.DlnI]*L1.DlnI[`last']+_b[L2.DlnI]*L2.DlnI[`last']+_b[L3.DlnI]*L3.DlnI[`last']+_b[L4.DlnI*L4.DlnI[`last']+_b[L1.DlnGDP]*L1.DlnGDP[`last']+_b[L2.DlnGDP]*L2.DlnGDP[`last']+///
      b[L3.DlnGDP]*L3.DlnGDP[`last']+b[L4.DlnGDP]*L4.DlnGDP[`last']+b[L1.UCCd]*L1.UCCd[`last']+///
      b[L2.UCCd]*L2.UCCd[`last']+b[L3.UCCd]*L3.UCCd[`last']+b[L4.UCCd]*L4.UCCd[`last']
      return scalar forecast=`fcast'
      return scalar actual=DlnI[`last'+1]
      end
      rolling actual=r(actual) forecast=r(forecast), recursive window(30):myforecast

      ----------------------- copy starting from the next line -----------------------
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double(DlnI DlnGDP UCCd) float t
              .         .         . 152
       .0168209  .0090275         . 153
       .0082655  .0074263         . 154
       .0493746  .0096827         . 155
      -.0210619  .0056343         . 156
      -.0192957  .0006199         . 157
       .0351725  .0176897         . 158
      -.0388222  .0136547         . 159
       .0364485  .0084038 -1.446258 160
       .0654373  .0060949 -1.097311 161
      -.0814295  .0028019 -.9224101 162
       .0214701  .0016632 -.5724914 163
      -.0086508  .0131178 -.3832499 164
       .0055971  .0078382 -.1861944 165
      -.0407562  .0074234 -.3602261 166
      -.0547781  .0044451 -.2087462 167
       .0230074  .0047379  -.457531 168
       .0527077  .0065737 -.8243707 169
      -.0315046  .0075512   .057045 170
       .0383701  .0089283  .6288664 171
       .0082273  .0065517  .3990892 172
       -.062335  .0094213 -.3131843 173
      -.0169582  .0101748 -.7190565 174
      -.0127773  .0080462 -.4422911 175
       .0213614  .0054579 -.5916772 176
       -.037466  .0038242 -1.037177 177
      -.0035152  .0016479 -.5653125 178
       .0063076  .0025177 -.4363043 179
       .0012798  .0094347 -.2388235 180
       .4928885  .0110292   .149464 181
      -.4112883   .011632  .5479603 182
      -.0219774  .0148706   .685739 183
        .014327  .0026598  .3896967 184
       .0148001  .0022259  .1834581 185
       .0533895  .0006409  .1488079 186
       .0186586   .003521  .2554978 187
       .0233641  .0099001  .5288669 188
       .0355253  .0071898  1.007599 189
      -.0389585  .0084343  1.240286 190
       .0752697  .0082855  1.525334 191
      -.0797148  .0035543  1.667388 192
       .0497026 -.0074291   3.02833 193
      -.0463734 -.0166063  3.043021 194
      -.0428619 -.0219536  4.940836 195
      -.0712824 -.0167656  3.358082 196
      -.0796061 -.0018978  1.338118 197
      -.0161839  .0014219 -.3770582 198
       .0021362  .0034561 -.9618227 199
       .0546284  .0044994 -.9779831 200
      -.0128117  .0085516 -1.262255 201
       .0415363  .0057659 -1.177879 202
       .0379152  .0013018 -.9774259 203
      -.0413361  .0074673 -.8778104 204
        .019268  .0014763 -.3904978 205
       .0451021  .0026875 -.3405398 206
       .0439062  .0016584  .4800186 207
       .0123453  .0064564  .4007746 208
      -.0509777 -.0005379  .2010778 209
       .0348234   .011838  .1026517 210
       .0720139 -.0022917    .03858 211
      -.0579185  .0064459 -.6948655 212
       .0024176  .0054684 -.6931425 213
       .0562916  .0089254 -.4242755 214
      -.0084648  .0046673 -.3285968 215
       .0054321  .0083475 -.6707458 216
       .0277872  .0082884 -.8899261 217
       .0016527  .0069838  -.817597 218
        .005991  .0066338 -.8806747 219
       .0320797   .004427 -.5022202 220
      -.0009117  .0056744 -.9857669 221
      -.0250607  .0043182 -.5253868 222
       .0223217  .0074043  -.251087 223
      -.0172024  .0032377 -.2409577 224
       .0086374  .0015631  -.253315 225
       .0150719  .0047064 -.4086905 226
      -.0100222  .0073872 -.7792494 227
      -.0020514  .0042448 -.7399015 228
       .0128136  .0026102 -.5922347 229
       .0087023  .0051641 -.2860989 230
       .0040102  .0039997 -.0707938 231
      -.0063362  .0005903  .2883179 232
      -.0043945  .0040674  .4002714 233
      -.0060863  .0068893  .5394858 234
      -.0089865   .002223  .8306352 235
       .0039072  .0049486  .7761144 236
              .         .         . 237
      end
      format %tq t
      ------------------ copy up to and including the previous line ------------------

      Last edited by Anja Heimann; 13 Jul 2019, 03:57.

      Comment

      Working...
      X