Downey, Patrick
2012-Mar-08 15:28 UTC
[R] Panel models: Fixed effects & random coefficients in plm
Hello, I am using {plm} to estimate panel models. I want to estimate a model that includes fixed effects for time and individual, but has a random individual effect for the coefficient on the independent variable. That is, I would like to estimate the model: Y_it = a_i + a_t + B_i * X_it + e_it Where i denotes individuals, t denotes time, X is my independent variable, and B (beta) is the coefficient on that random variable. I want both a coefficients to be estimated with fixed effects because I expect them to be correlated with Y, and B to be estimated using a random effect. I understand how to estimate two way fixed effects models in plm (which have the fixed effects for time and individual, as I want) and how to estimate random coefficient models (which have random effects for all coefficients, including the intercept and the beta). I want to combine these, though, and I cannot figure out how to do that. It seems like the plm package is capable, but I can't figure it out. Below is reproducible code (assuming you have plm installed) taken from the vignette available on cran. It shows the two models I know how to estimate. Any guidance on estimating the third model would be greatly appreciated. -Mitch # Data setup library(plm) data("EmplUK", package="plm") names(EmplUK) E <- pdata.frame(EmplUK, index = c("firm", "year"), drop.index = TRUE, row.names = TRUE) # Two-way fixed effects model with constant beta m1 <- plm(wage ~ output,data=E,model="within",effect="twoways") summary(m1) # Random (individual) effects for both intercept and beta m2 <- pvcm(wage ~ output,data=E,model="random") summary(m2)
Millo Giovanni
2012-Mar-12 17:42 UTC
[R] Panel models: Fixed effects & random coefficients in plm
Hello. Such a procedure is not implemented in 'plm' but you can probably get around to do what you want. One possible way (my preferred one) is to demean the data by both dimensions as you would do for a two-way FE model, and then estimate a random parameters model on the demeaned data. This would get you rid of fixed effects both ways, although inducing correlation in the residuals (something I don't think is particularly harmful in your case, but this is just a quick opinion...). To do this you can in fact use infrastructure from 'plm', e.g. using model.matrix() and pmodel.response(); or you can do it by hand in base R. Another way is to explicitly add time and individual dummies, including 'as.factor(<indvar>)' and 'as.factor(<timevar>)' to the specification; this way, though, you will be estimating the relative coefficients as random parameters instead than fixed as well. A third possibility, outside 'plm', is to check in the 'nlme' package (lme() function) whether such a specification is possible at all: I think it is, putting the two sets of dummies as "fixed" parameters and your beta at "random". Best wishes, Giovanni Giovanni Millo, PhD Research Dept., Assicurazioni Generali SpA Via Machiavelli 4, 34132 Trieste (Italy) tel. +39 040 671184 fax +39 040 671160 ###################### original message ################## Message: 42 Date: Thu, 8 Mar 2012 10:28:40 -0500 From: "Downey, Patrick" <PDowney at urban.org> To: <r-help at r-project.org> Subject: [R] Panel models: Fixed effects & random coefficients in plm Message-ID: <0F96478603980B46AAAFBA77069582ED18B39D0C at UIEXCH.urban.org> Content-Type: text/plain; charset="us-ascii" Hello, I am using {plm} to estimate panel models. I want to estimate a model that includes fixed effects for time and individual, but has a random individual effect for the coefficient on the independent variable. That is, I would like to estimate the model: Y_it = a_i + a_t + B_i * X_it + e_it Where i denotes individuals, t denotes time, X is my independent variable, and B (beta) is the coefficient on that random variable. I want both a coefficients to be estimated with fixed effects because I expect them to be correlated with Y, and B to be estimated using a random effect. I understand how to estimate two way fixed effects models in plm (which have the fixed effects for time and individual, as I want) and how to estimate random coefficient models (which have random effects for all coefficients, including the intercept and the beta). I want to combine these, though, and I cannot figure out how to do that. It seems like the plm package is capable, but I can't figure it out. Below is reproducible code (assuming you have plm installed) taken from the vignette available on cran. It shows the two models I know how to estimate. Any guidance on estimating the third model would be greatly appreciated. -Mitch # Data setup library(plm) data("EmplUK", package="plm") names(EmplUK) E <- pdata.frame(EmplUK, index = c("firm", "year"), drop.index = TRUE, row.names = TRUE) # Two-way fixed effects model with constant beta m1 <- plm(wage ~ output,data=E,model="within",effect="twoways") summary(m1) # Random (individual) effects for both intercept and beta m2 <- pvcm(wage ~ output,data=E,model="random") summary(m2) ###################### end original message ################## ? Ai sensi del D.Lgs. 196/2003 si precisa che le informazi...{{dropped:12}}