Search code examples
rdummy-variablearima

Add quarterly dummy to ARIMA model


My data is a time series.

y <- ts(datafile[,"y"], start=1960, frequency=4, end=2010)

I want to include quarterly dummies in my forecasting ARIMA model. Is that possible? If so, what's the command for it? I can't seem to find one which allows me to merge the ARIMA model with the quarterly dummy variable.

So my ARIMA model is:

fit_y <- arima(y, order=c(2,1,2), method="ML")

I know how to fit seasonal ARs into the model:

fit_y <- arima(y, order=c(2,1,2), seasonal=list(order=c(0,1,1), period=4), method="ML")

Is there a way to include a quarterly dummy variable? I've created the dummy variables - manually - through excel and titled them Q1, Q2, Q3, Q4, with the following specification so that R reads them as a time series variable:

Q1 <- ts(datafile[,"Q1"], start=1960, frequency=4, end=2010)
Q2 <- ts(datafile[,"Q2"], start=1960, frequency=4, end=2010)
Q3 <- ts(datafile[,"Q3"], start=1960, frequency=4, end=2010)
Q4 <- ts(datafile[,"Q4"], start=1960, frequency=4, end=2010)

Solution

  • You can add the dummy variables to the arima model via the option xreg of arima.

    y <- ts(datafile[,"y"], start=1960, frequency=4)
    Q1 <- ts(rep(c(1,0,0,0),44), start=1960, frequency=4)
    Q2 <- ts(rep(c(0,1,0,0),44), start=1960, frequency=4)
    Q3 <- ts(rep(c(0,0,1,0),44), start=1960, frequency=4)
    xreg <- cbind(Q1,Q2,Q3)
    
    fit_y <- arima(y, order=c(2,1,2), method = "ML", xreg = xreg)
    

    Note that (i) I didn't add the Q4, to avoid the dummy trap (see for example question about dummy trap ), and (ii) that you can easily generate these Q1, Q2 and Q3 in R.