I am estimating the following panel data twoways fixed effect model:

y = alfa*y.lag + beta1*z + beta2*z^2 + theta*id + gamma*t     (1)

where id is the individual effect, t is the time effect. I am using the {plm} package in r, therefore the code goes like this

fe.full <- plm(y ~ lag(y, 1) + z +z2, data = mdt, model= "within", effect="twoways")

Now I need to "extract" the predicted value for y. I know it can be done by doing predict(fe.full), however I need to do that by hand for comparing it with other models specifications. Summing alfa*y.lag + beta1*z + beta2*z^2 is not enough since I have to consider the coefficients for id and t. I know that the former can be obtained as fixef(fe.full). However I dont know how to extract the value for the time effect. In Stata coefficients for time are displayed in the summary of the model. In R I was not able to manage that. I also tried to sum the coefficients for time taken from Stata to the value of X*coeff + fixef(fe.full) obtained in R, but still the output is not equal to the value given by predict(fe.full). So I am doing something wrong, I guess.

Therefore the question is : how can I compute manually the sum of the right hand side of equation (1) starting from a plm object ?

  • $\begingroup$ You get the time effects with fixef(your_model, effect = "time"). $\endgroup$ – Helix123 Jun 10 '17 at 9:48

Well I finally managed it out, applying the suggestions by the authors of the plm package here http://r.789695.n4.nabble.com/fitted-from-plm-td3003924.html

So what I did is just to apply

fitted <- as.numeric(fe.full$model[[1]] - fe.full$residuals) 

where I need the as.numeric function since I need to use it as a vector to plug in for further manipulations. I also want to point out that if your model has a lagged dependent variable on the right hand side, the solution above with as.numeric provides a vector already NET of the missing values because of the lag. For me this is exactly what I needed to.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.