tests/test_Errors.R

### Testing problematic and erroneous data
library(plm)

### NA in the individual index: should give an informative error
ind <- 1:100
ind[4] <- NA
T <- 4
                           # balanced panel of length 4
alpha <- rnorm(length(ind))
                           # fixed effects
eps <- rnorm(T*length(ind))
                           # idiosyncratic effect
x <- runif(length(ind))
y <- x + alpha + eps
dat <- data.frame(y, x, ind=rep(ind, T), t=rep(1:T, each=length(ind)))
data <- pdata.frame(dat, index=c("ind", "t"))
a <- try(m <- plm(y ~ x, data=data, model="random"))
                           # should give an error: NA in the individual index

Try the plm package in your browser

Any scripts or data that you put into this service are public.

plm documentation built on Sept. 21, 2021, 3:01 p.m.