title: Panel estimation with Stata - how to do by data subsets
body: <p>I need to run regressions on both OLS and fixed effects panel models. The dependent variable is arranged by a group variable. The OLS proceeds like this:</p>
  
  <pre><code>sysuse data, clear
  bysort group: reg depVar expVar1 expVar2
  </code></pre>
  
  <p>That works as it should. However, I have not managed to make this work with panel data:</p>
  
  <pre><code>sysuse data, clear
  xtset id year
  bysort group: xtreg depVar expVar1 expVar2, fe
  </code></pre>
  
  <p>However, an error terminates the process after defining the panel variables because there are duplicate observations. That is not a "real" error because after sorting by group there would be no duplicates.</p>
  
  <p>I know that I could reshape the data to wide format and type a separate line for each estimation, but I am wondering whether there are other, more convenient ways around this.</p>