title: How do I generate a mean by year and industry in Stata
body: <p>I'm trying to generate in Stata the mean per year (e.g. 2002-2012) for each industry (by 2 digit SIC codes, so c. 50 different industries)</p>
  
  <p>I found how to do it for one year with:</p>
  
  <pre><code>by sic_2digit, sort: egen test = mean(oancf_at_rsd10) if fyear == 2004
  </code></pre>
  
  <p>Is there a more efficient way to do this instead of repeating the command 10 times by hand and than adding the values together?</p>