It seems that pcdtest is no implemented for unbalanced panels. Weird enough it works with tiny unbalancedness but not with larger ones...
Here a reproducible example:
library(plm)
#in a data.frame like this:
testData <- data.frame(id=c(rep(1:200,each=20)),time=rep(1991:2010,200),
var1=rnorm(4000,10)/1000,var2=rnorm(4000,123))
#pcdtest will work:
pcdtest(var1 ~ var2, data=testData,
model="within")
#even with slight unbalancedness:
testData1 <- testData[-(3:4),]
pcdtest(var1 ~ var2, data=testData1,
model="within")
#but not with slightly larger ones:
testData2 <- testData[-(3:30),]
pcdtest(var1 ~ var2, data=testData2,
model="within")
I do not know where the treshold is exactly or why it does not work.
To be honest, I'm starting to loose my faith in real world applications of plm
which is a pity because it implements exactly what is usually needed. ItHowever, it performs quite badly with many fixed effects (so pretty much every panel application after 1995 in economics) and often times even breaks down (just compare a large panel dataset where you do the within transformations yourself followed by lm() with an model=within,effects=twoways plm attempt). It also has troubles with unbalanced panels many times from my experience... Maybe pglm
is better?