I am forecasting GDP growth for my dissertation. The data is from 1984-2017 (quaterly values). I am using the following code to fit and forecast a linear regression model.

ts(GDPgrowth, start = 1984, end = 2017, frequency = 4)
ts(spread, start = 1984, end = 2017, frequency = 4)

---sample of the first 27 observations---

model = lm(GDPgrowth ~ spread, data= mydata[1:27, ])
prediction = predict(model, mydata[28:38, ], type = "response")

---this works and i get the predicted values for observations 28-38. now when i try the same for the entire data set i get NA for all the valued beyond 2017.---

model1 = lm(GDPgrowth ~ spread, data= mydata)
prediction1 = predict(model, mydata[134:145, ], type = "response")

1 2 3 4 5 6 7 8 9 10 11 12 1.064371 NA NA NA NA NA NA NA NA NA NA NA

I have heard about using for loops to forecast but i am a beginner to r and world appreciate any help. thanks.

  • 1
    $\begingroup$ Do you have a forecast of spread after 2017? $\endgroup$ – Chris Haug Jul 23 '18 at 11:24
  • $\begingroup$ No. I don’t. Would I need those values to forecast gdp growth? $\endgroup$ – Angela wells Jul 23 '18 at 12:20

The model you defined above looks like this (where GDP growth is $G_t$ and spread is $S_t$):

$$G_t = a + bS_t + \varepsilon_t$$

It is a conditional model of $G_t$, given $S_t$. If you have a value of $S_t$ for a given $t$ as input, it will output an estimate of $G_t$ for that same date (the mean of $G_t$ conditional on $S_t$, for example). This means that you can only obtain estimates of GDP growth on dates where you already observed spread, so it is not really a "forecast" (although, given the delay with which GDP data is typically published, it's possible to have the spread data available well before GDP for the same date; people usually refer to this as "nowcasting").

In short, this model does not know anything about what GDP growth should be if you don't also know what the spread is for the same date.

If you want to obtain actual forecasts for GDP growth, you have several options, for example:

  • You can model the dynamics of $S_t$ only (i.e. $S_t$ conditional on $S_1, ..., S_{t-1}$), for example with an ARIMA or ETS model, or any other time series model, obtain a point forecast for that variable and plug it in to your other equation. There's some issues there with computing the prediction intervals but you can get a point forecast easily.
  • In a similar vein, you can use point forecasts for the spread that may be published in expert surveys or the like, although typically there you will not be able to compute a prediction interval at all.
  • You can model the dynamics of $S_t$ and $G_t$ jointly, for example in a VAR or VECM model. This would use both variables together to forecast each other together.
  • If you are not really interested in the relationship between $S_t$ and $G_t$ but really just want to forecast $G_t$, you can model the dynamics of $G_t$ alone, and forecast it based on its own history.

If you are interested in the relationship between the two and not just trying to forecast GDP growth, the joint modelling of both variables will probably be the most useful.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.