title: Hausman type test in R
body: <p>I have been using "<strong>plm</strong>" package of <strong>R</strong> 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 <strong>Hausman type</strong>. A similar test is also available for the Stata. The point here is that <strong>Stata</strong> 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 "<strong>plm</strong>" 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. </p>
  
  <pre><code>*
  
  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 &lt;- plm(y~X1+X2+X3+X4,data=mydata,model="within")
  summary(model.fe)
  #step 2 : Estimate the RE model
   re &lt;- pggls(y~X1+X2+X3+X4,data=mydata,model="random")
  summary(model.re)
  #step 3 : Run Hausman test
  phtest(fe, re)
  </code></pre>