I have been using "plm" package of R to do the analysis of panel data. One of the important test in this package for choosing between "fixed effect" or "random effect" model is called Hausman type. A similar test is also available for the Stata. The point here is that Stata requires fixed effect to be estimated first followed by random effect. However, I didn't see any such restriction in the "plm" package. So, I was wondering whether "plm" package has the default "fixed effect" first and then "random effect" second. For your reference, I mention below the steps in Stata and R that I followed for the analysis.
*
Stata Steps: (data=mydata, y=dependent variable,X1:X4: explanatory variables)
*step 1 : Estimate the FE model
xtreg y X1 X2 X3 X4 ,fe
*step 2: store the estimator
est store fixed
*step 3 : Estimate the RE model
xtreg y X1 X2 X3 X4,re
* step 4: store the estimator
est store random
*step 5: run Hausman test
hausman fixed random
#R steps (data=mydata, y=dependent variable,X1:X4: explanatory variables)
#step 1 : Estimate the FE model
fe <- plm(y~X1+X2+X3+X4,data=mydata,model="within")
summary(model.fe)
#step 2 : Estimate the RE model
re <- pggls(y~X1+X2+X3+X4,data=mydata,model="random")
summary(model.re)
#step 3 : Run Hausman test
phtest(fe, re)
Update: Be sure to read the comments. Original answer below.
Trial-and-error way of finding this out:
> library(plm)
> data("Gasoline", package = "plm")
> form <- lgaspcar ~ lincomep + lrpmg + lcarpcap
> wi <- plm(form, data = Gasoline, model = "within")
> re <- plm(form, data = Gasoline, model = "random")
> phtest(wi, re)
Hausman Test
data: form
chisq = 302.8037, df = 3, p-value < 2.2e-16
alternative hypothesis: one model is inconsistent
> phtest(re, wi)
Hausman Test
data: form
chisq = 302.8037, df = 3, p-value < 2.2e-16
alternative hypothesis: one model is inconsistent
As you can see, the test yields the same result no matter which of the models you feed it as the first and which as the second argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With