'Time series and differencing for stationarity when using nmle::gls vs. TSA::arimax
I am using nmle:gls for dynamic time serie4s analysis exploring the interplay between two variables. I am also adjusting the model for a variable capturing a policy change(coded as 0 before the introduction of the policy and 1 afterwards).
The outcome variable is not stationary so I am differencing the data to make it stationary.
I noticed that when I run the model using TSA::arimax for comparison, the programme appears to difference all the variables within the model, i.e. the DV as well as the two variables specified as IV, including the policy which is just a binary variable.
install.packages("car")
install.packages("nlme")
install.packages("TSA")
data = carData::Hartnagel
View(data)
head(data)
# Let's assume policy change in 1955
data$policy = ifelse(data$year>=1955, 1, 0)
### ARIMA analysis
iv = matrix(ncol=2, nrow=nrow(data))
colnames(iv) = c("TFR", "Policy")
iv[,1] = data$tfr
iv[,2] = data$policy
iv = as.data.frame(iv)
dv = ts(data = data$fconvict, frequency=1, start= data[1, "year"])
mod.arimax = TSA::arimax(dv, order=c(1,1,0), seasonal=list(order=c(0,0,0),
period=1),
xtransf=iv[,1], transfer=list(c(0,0)),
xreg = iv[,2],
transform.pars = FALSE, optim.control = list(maxit = 1000))
summary(mod.arimax)
This seems counterintuitive and I am left wondering whether I should do the same when using nmle::gls if I wanted to get similar results or whether it is wrong and policy should be entered as it was created.
data = dplyr::mutate(data, tfrDiff = c(NA, diff(tfr, difference = 1)))
data = dplyr::mutate(data, fconvictDiff = c(NA, diff(fconvict, difference = 1)))
data = dplyr::mutate(data, policyDiff = c(NA, diff(policy, difference = 1)))
### GLS
mod.gls = gls(fconvictDiff ~ tfrDiff+policyDiff-1, data = data,
correlation=corARMA(p=1), method="ML", na.action=na.omit)
summary(mod.gls)
Any input on this would be much appreciated!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
