I am trying to generate a 1-step-ahead forecast of a quarterly variable using a monthly variable with the midasr
package. The trouble I am having is that I can only estimate a MIDAS
model when the number of monthly observations in the sample is exactly 3 times as much the number of quarterly observations.
How can I forecast in the midasr
package when the number of monthly observations is not an exact multiple of the quarterly observations (e.g. when I have a new monthly data point that I want to use to update the forecast)?
As an example, suppose I run the following code to generate a 1-step-ahead forecast when I have (n)
quarterly observations and (3*n)
monthly observations:
#first I create the quarterly and monthly variables
n <- 20
qrt <- rnorm(n)
mth <- rnorm(3*n)
#I convert the data to time series format
qrt <- ts(qrt, start = c(2009, 1), frequency = 4)
mth <- ts(mth, start = c(2009, 1), frequency = 12)
#now I estimate the midas model and generate a 1-step ahead forecast
library(midasr)
reg <- midas_r(qrt ~ mls(qrt, 1, 1) + mls(mth, 3:6, m = 3, nealmon), start = list(mth = c(1, 1, -1)))
forecast(reg, newdata = list(qrt = c(NA), mth =c(NA, NA, NA)))
This code works fine. Now suppose I have a new monthly data point that I want to include, so that the new monthly data is:
nmth <- rnorm(3*n +1)
I tried running the following code to estimate the new model:
reg <- midas_r(qrt ~ mls(qrt, 1, 1) + mls(nmth, 2:7, m = 3, nealmon), start = list(mth = c(1, 1, -1))) #I now use 2 lags instead 3 with the new monthly data
However I get an error message saying: 'Error in mls(nmth, 2:7, m = 3, nealmon) : Incomplete high frequency data'
I could not find anything online on how to deal with this problem.
A while ago I had to do with similar question. If I remember correctly, you first need to estimate the model using the old dataset with reduced lag, so insted of using 3:6
lags you should use 2:6
lags:
reg <- midas_r(qrt ~ mls(qrt, 1, 1) + mls(mth, 2:6, m = 3, nealmon), start = list(mth = c(1, 1, -1)))
Then suppose you observe a new value of the higher frequency data - new_value
new_value <- rnorm(1)
Then you can use this newly observed value for the forecasting of the lower frequency valiable as follows:
forecast(reg, newdata = list(mth = c(new_value, rep(NA, 2))))