Unit root tests for panel data in R 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?

 A: 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

A: Did you try to convert your data to pdata.frame? I have an unbalanced panel also, but purtest seems to work with unbalanced panel if the data is pdata.frame. But I might be wrong too:)
However in ?purtest authors write: 
"object, x  

Either a 'data.frame' or a matrix containing the time series, 
a 'pseries' object, a formula, or the name of a column of a 'data.frame',
or a **'pdata.frame'**
on which the test has to be computed; a'purtest' object for the print 
and summary methods,"

So I guess if one uses pdata.frame the purtest "understands" that panel is unbalanced.
Am I wrong???
A: You can use for sure the IPS test on unbalanced data, as long as you test for the Wtbar or Ztbar statistic.
Fore example, the following R code can be used to test sattionarity in unbalanced heterogeneous panel data, with IPS test (plm package):
`purtest(data$tot.emp, test = c("ips"), ips.stat="Ztbar", exo="intercept",dfcor=TRUE, lags = c("AIC"), pmax = 10)`

A: Eviews 5 allows you to test the panel unit roots for the unbalanced data that is not possible with R and Stata. For example, even though Im–Pesaran–Shin and Fisher-type tests can be applied for unbalanced panel in Stata, it is not possible if we have some observations , with the gap i.e. we have data of country i for year 2002 and 2004 but not 2003 (assuming the lag to be greater than one). I think that Eviews drop all such observations while performing tests, for our example this is country i. However, if you manually drop all such observations, you can still perform the tests with R and Stata. 
