[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


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")

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.


More information about the R-help mailing list