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)