I am trying to predict set values โโover data containing NA s, and based on the model generated by plm . Here is a sample code:
require(plm) test.data <- data.frame(id=c(1,1,2,2,3), time=c(1,2,1,2,1), y=c(1,3,5,10,8), x=c(1, NA, 3,4,5)) model <- plm(y ~ x, data=test.data, index=c("id", "time"), model="pooling", na.action=na.exclude) yhat <- predict(model, test.data, na.action=na.pass) test.data$yhat <- yhat
When I run the last line, I get an error message indicating that the replacement has 4 lines, while the data has 5 lines.
I have no idea how to get the prediction to return a vector of length 5 ...
If instead of running plm start lm (as in the line below), I get the expected result.
model <- lm(y ~ x, data=test.data, na.action=na.exclude)