title: Clustered robust standard errors on country-year pairs
body: <p>I want to replicate a Stata do.file (panel model) in R, but unfortunately I'm ending up with the wrong standard error estimates. The data is proprietary, so I can't post it here. The Stata code used looks like: </p>
  
  <pre><code>xtreg  Y X, vce(cluster countrycodeid) fe nonest dfadj 
  </code></pre>
  
  <p>With <code>fe</code> for fixed effects, <code>nonest</code> indicating that the panels are not nested within the clusters, and <code>dfadj</code> for the fact that some sort of DF-adjustment takes place - not possible to find out which sort as of now.</p>
  
  <p>My R-Code looks like this and makes me end up with the right coefficient values:</p>
  
  <pre><code>model &lt;- plm(Y~X+as.factor(year),data=panel,model="within",index=c("codeid","year"))
  </code></pre>
  
  <p>Now comes the difficult part, which I haven't found a solution for so far, even after trying out numerous sorts of standard error robust estimation methods, for example making extensive use of <code>lmtest</code> and various degrees of freedom transformation methods. The standard errors are supposed to follow a country-year pair pattern (captured by the variable <code>countrycodeid</code> in the Stata code, which takes the form codeid-year, as there appears to be missing data for some variables which are not available on a monthly basis.</p>
  
  <p>Does anyone know if there are special tricks to keep in mind when working with unbalanced panels and the <code>plm()</code> package, which sort of DF-adjustment can be used, and if there is a possibility to group data in the <code>coeftest()</code> function on a country-year basis?</p>