Unit Root Tests for Panel Data in R: A Comprehensive Guide

panel datarunit root

I have the plm package and would like to run unit root tests on some variables. I get the following error:

> purtest(data$tot.emp)
Error in data.frame(baldwin = c(59870, 61259, 60397, 58919, 57856, 57227,  : 
  arguments imply differing number of rows: 14, 19, 11, 12, 1, 20, 18, 10, 13

I assume that I'm getting this error because my panel is unbalanced. Two questions:

  • Can you use panel unit root tests (Levin, Lin and Chu (2002), Im, Pesaran and Shin (2003), or others) for unbalanced panels?
  • If so, is it implemented in R?

Best Answer

At the current moment (version 1.2-10, 2012-05-05) it seems that the unbalanced case is not supported. Edit: The issue of unbalanced panel data is solved in version 2.2-2 of plm on CRAN (2020-02-21).

Rest of the answer is assuming version 1.2-10:

I've looked at the code, and the final data preparation line (no matter what is your initial argument) is the following:

 object <- as.data.frame(split(object, id))

If you pass unbalanced panel, this line will make it balanced by repeating the same values. If your unbalanced panel has time series with lengths which divide each other then even no error message is produced. Here is the example from purtest page:

 > data(Grunfeld)
 > purtest(inv ~ 1, data = Grunfeld, index = "firm", pmax = 4, test = "madwu")

Maddala-Wu Unit-Root Test (ex. var. : Individual Intercepts )

  data:  inv ~ 1 
  chisq = 47.5818, df = 20, p-value = 0.0004868
  alternative hypothesis: stationarity 

This panel is balanced:

 > unique(table(Grunfeld$firm))
  [1] 20

Disbalance it:

 > gr <- subset(Grunfeld, !(firm %in% c(3,4,5) & year <1945))

Two different time series length in the panel:

 > unique(table(gr$firm))
  [1] 20 10

No error message:

> purtest(inv ~ 1, data = gr, index = "firm", pmax = 4, test = "madwu")
 
    Maddala-Wu Unit-Root Test (ex. var. : Individual Intercepts )

data:  inv ~ 1 
chisq = 86.2132, df = 20, p-value = 3.379e-10
alternative hypothesis: stationarity 

Another disbalanced panel:

  > gr <- subset(Grunfeld, !(firm %in% c(3,4,5) & year <1940))
  > unique(table(gr$firm))
  [1] 20 15

And the error message:

 > purtest(inv ~ 1, data = gr, index = "firm", pmax = 4, test = "madwu")
  Erreur dans data.frame(`1` = c(317.6, 391.8, 410.6, 257.7, 330.8, 461.2,  : 
  arguments imply differing number of rows: 20, 15
Related Question