[R] fixef.plm: Extract the Fixed Effects
Jayashree Raman
j@y@@hreer@m@n @ending from berkeley@edu
Sun Oct 21 03:08:04 CEST 2018
Hello,
I am trying to predict using a fixed effects model on an unbalanced
panel. I tried using the code in the example but the fitted values I
get are very different from the fitted values using observed value -
residual. I am giving my code snippet here:
train_data <- na.omit(read.csv(file="usersessions-with-char-sec-train-subset-100.csv",
header=TRUE, row.names = NULL, sep="|"))
panel.data.train <- plm.data(train_data, index = c("session_start","userid"))
mdl_fe <-plm(session_length~age+session_length_mvavg, data =
panel.data.train, model = "within")
##Summaries
summary(mdl_fe)
fixefs <- fixef(mdl_fe)[index(mdl_fe, which = "userid")]
fit_hand <- fixefs + mdl_fe$coefficients[1] * panel.data.train$age +
mdl_fe$coefficients[2] * panel.data.train$session_length_mvavg
fitval <- panel.data.train$session_length-mdl_fe$residuals
Also when I tried the prediction function from the prediction package,
I get the following error:
Error in crossprod(beta, t(X)) : non-conformable arguments
Any help is appreciated.
Thanks!
Jayashree
More information about the R-help
mailing list