Question

Hello and thanks in advance. I'm trying to run a unit root test on a subset of series X after it has been differenced, X_diff

X_diff <- diff(X, differences = 1)

urdfTest( subset(X_diff, dat[["Year"]] > 2001 ), lags = 4, type = c("c"), doplot = TRUE)

I get the following error: 'Error in na.fail.default(as.ts(x)) : missing values in object'

Now I noticed that if I view the entire X_diff variable, I get no NA values. However, if I view the subset of X_diff variable (code below) I get an NA value all the way at the end, and this is true for any year I place into the condition.

TBG_diff[which(dat[["Year"]] > 2001)]

Why does the NA appear and how can I run the subset of the differenced series without getting the NA error?

Était-ce utile?

La solution

I bet the problem is that you have differenced, so, one end of the differences is looking for a year that doesn't exist (either the year before the first year you have data for, or the year after the last year you have data for).

The solution would be to difference for a set that is one year shorter than your actual set of years

EDIT

Thinking about it some more, I think you should subset before you difference rather than the other way around. Something like

X_2001 <- subset(X, dat[["Year"]] > 2001)
urdfTest(X_2001, MORE CODE HERE)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top