Testing strategy for unit root tests: solution to make it extremely easy and fast

Share:

Only few econometric books teach us which strategy we should follow when performing unit root tests. I mean, when you have a time series, how you should proceed to perform the unit root test (to determine if you need a trend, for example). In general, there are two main approaches. One is the Enders (2004) and the other is the Elder and Kennedy (2001). Hatemi-J and Hacker (2010) developed Monte Carlo simulations to compare them and they found that the latter strategy improves the power of the Augmented Dickey Fuller (ADF) test.

To reduce the possibility of getting unreasonable results, Elder and Kennedy (2001) suggest to incorporate to the testing strategy the previous knowledge about the growth status of the series. I will not describe the different options that imply each knowledge about the growth status of the series because the paper has a clear explanation and concise (10 pages long). Then, we have three possibilities:

Is it growing?

Is it uncertain its growth status?

Is it not growing?

If the series is in levels and it has not experienced a negative growth rate during the period: How can our unit root test strategy consider the possibility of stationarity? This is what the Elder and Kennedy (2001) approach warn us about.

Considering this, I wrote a code that follows the Elder and Kennedy (2001) strategy. Then, given your assumption about the growth status of a group of series, the code devolves the initial and the definitive result of the ADF test corrected for autocorrelation. If you don’t know why I am talking about correcting the autocorrelation, it will be useful for you to read this post. It is important to say that the decision about if it is needed a trend or intercept is always based on a 0.05 significance level.

As a recurrent practice in my posts, I will try to keep the codes as simple to understand as I can (or better, I think I can). My main purpose is that anyone that want to start learning coding, this codes can help them to improve their coding skills. If you are not able to understand the code, you can work with it for a while and get familiar and confident with it. On the other hand, the readers with coding experience, can easily check by them selves what the code is doing.

Getting ready to use the code.

This code requires the R package urca. To install it in Windows or Mac,

  1. Go to the menu of RStudio and click on Tools and after on Install Packages…
  2. Then, in “Packages (separate multiple with space or comma):” write urca and RStudio will install both packages
  3.  Just in case, go to the low-right side panel of the screen of RStudio and click in the Packages window. Then, search there the urca packages and verify that it is checkmarked.

To load your data go the menu of RStudio and click on File and after on Import Dataset. That will import the database as data.frame object, but it need to be a matrix object. Imagine that you named the imported database mydata. Then you just need to write in the R Console

mydata<-as.matrix(mydata)

And your database is ready to be imputed in the code.

Explanation of the code.

I called the function (or the code) adfstrategy and it has the following arguments

adfstrategy<-function(y, status = “unknown”, lags = 14, selectlags = “AIC”, order =5, order.by = NULL, q = 40, pvalu = 0)

Where:

  1. y is the database. The first column should be the time and it should be a matrix object (if it is a data.frame object, will not work). I will explain later how to import the data. Important, you don’t need to remove the NAs, because the code will remove them series by series. This means that if you have NAs and you want to perform the ADF tests for a fixed period, it is better for you to input the matrix for the period that you want (a period free of NAs).
  2. status is your perception about the growth status of all the series contained in the matrix. If in your matrix there are series that are growing and other that aren’t, you can set the argument status=”growing” and after status=”unknown” or status=”nogrow”.
  3. lags and selectlags are arguments of the function ur.df contained in the urca R package. Then, lags refer to up to how many lags you will allow to get the optimal lag in the ADF specification and selectlags refer to which criteria you want to use to select that optimal lag.
  4. order and order.by are arguments of the function bgtest (it performs the Breusch–Godfrey tests to check for autocorrelation. Then, order will contain up to which order autocorrelation you want to check in the ADF specification. If you set order = 3, the code will check for first, second and third order autocorrelation.
  5. q is up to how many lags you want to go in order to correct autocorrelation problems in the ADF specification. Of course, you should set q ≥ lags.
  6. pvalu is the significance level for the Breusch Godfrey tests. As the decisions about it is needed a trend or a constant is exclusively based on a 0.05 level of significance, it seems that it is better to set pvalu = 0.05 (if you want the correction for autocorrelation, of course). If you don’t want the results corrected for autocorrelation, you can just set the argument “pvalu”=0 (as all probabilities are larger than 0, the code will not correct for autocorrelation).

Getting started with the code

In order to see how is the output of the code and to show how the code works, I prepared a YouTube video explaining the code.

If your mother language is Spanish or you have an advanced knowledge of it, you can watch the Spanish video because my English is quite broken.

Finally, you can download the code in its Github repository. Please, comment if you have any question about the code.