title: Clustered standard errors in R using plm (with fixed effects)
body: <p>I'm trying to run a regression in R's <code>plm</code> package with fixed effects and <code>model = 'within'</code>, while having clustered standard errors. Using the <code>Cigar</code> dataset from <code>plm</code>, I'm running: </p>
  
  <pre><code>require(plm)
  require(lmtest)
  data(Cigar)
  model &lt;- plm(price ~ sales + factor(state), model = 'within', data = Cigar)
  coeftest(model, vcovHC(model, type = 'HC0', cluster = 'group'))
  
    Estimate Std. Error t value Pr(&gt;|t|)    
  sales  -1.21956    0.21136 -5.7701 9.84e-09
  </code></pre>
  
  <p>This is (slightly) different than what I'd get by using Stata (having written the Cigar file as a .dta):</p>
  
  <pre><code>use cigar
  
  xtset state year
  
  xtreg price sales, fe vce(cluster state)
  
  
  price   Coef.   Std. Err.   t   P&gt;t [95% Conf.  Interval]
  
  sales   -1.219563   .2137726    -5.70   0.000   -1.650124   -.7890033
  </code></pre>
  
  <p>Namely, the standard error and T statistic are different. I've tried rerunning the R code with different "types", but none give the same result as Stata. Am I missing something?</p>