I am trying to fully understand the ins and outs of the plm package in R. I have a dataset where I computed a fixed effects plm:
mydata <- read.spss("G:/data.sav",use.value.labels=TRUE, to.data.frame = TRUE)
attach(mydata)
Y <- cbind(Y)
X <- cbind(x1,x2,x3)
pdata <- plm.data(mydata, index=c("id","YEAR"))
fixed <- plm(Y ~ X, data=pdata, model= "within")
I am trying to calculate both the training and test dataset predicted values. I found some material on CV here that kind of addresses what I am trying to do, but does not completely answer it. When I calculate by hand:
y = beta1*z + beta2*z + theta*id
the predicted values from
fitted <- as.numeric(fixed$model[[1]] - fixed$residuals)
are not the same as when I sum beta*x1 + beta*x2 + beta*x3 + fixef(fixed).
Basically I am trying to figure out how to calculate by hand the in sample predicted values so I can run the calculations for the out of sample data.
Can anyone explain what I maybe doing wrong in doing the calculation by hand?