title: Stata: sales growth rate of multiple groups
body: <p>Cross-posting:
  german: <a href="http://www.stata-forum.de/post1716.html#p1716" rel="nofollow noreferrer">http://www.stata-forum.de/post1716.html#p1716</a>
  english: <a href="http://www.talkstats.com/showthread.php/47299-sales-growth-rate-with-multiple-groups-conditions" rel="nofollow noreferrer">http://www.talkstats.com/showthread.php/47299-sales-growth-rate-with-multiple-groups-conditions</a></p>
  
  <p>I want to calculate the annual sales growth rate of different firm-groups in Stata. The firms are grouped by variables <code>country</code> and <code>industry</code>. </p>
  
  <p>I summed sales for each group (called it <code>sales_total</code>: sales of all firms in a group with equal <code>country</code>, <code>industry</code> and <code>year</code>):</p>
  
  <pre><code>bysort country year industry: egen sales_total = sum(sales)
  </code></pre>
  
  <p>I have a much bigger sample, but I tried to calculate the growth-rate with a smaller sample.</p>
  
  <p>I tried multiple combinations such as:</p>
  
  <pre><code>egen group = group(year country industry)
  xtset group year, yearly
  bys group: g salesgrowth = log(D.sales_total)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>bysort group: gen salesgrowth=(sales[_n]-sales[_n-1])/sales[_n-1]*
  </code></pre>
  
  <p>also with <code>tsset</code>.</p>
  
  <p>and tried everything from this answer:
  <a href="https://stackoverflow.com/questions/10254082/generate-percent-change-between-annual-observations-in-stata/10259827#10259827">Generate percent change between annual observations in Stata?</a></p>
  
  <p>but I always get error messages such as </p>
  
  <pre><code>  repeated time values within panel 
  </code></pre>
  
  <p>or </p>
  
  <pre><code> repeated time values within sample
  </code></pre>
  
  <p>due to the repetition of the number in a variable such as <code>group</code>.</p>
  
  <p>Can you help me to find the yearly growth rate from each group (firms from same <code>country</code> &amp; <code>industry</code>)? </p>
  
  <p><strong>update</strong></p>
  
  <p>here again an example of my observations (which normally have 10,000 firms over 10 years). There are also missing values (for sales, industry, year, country)</p>
  
  <p>firms -- country -- year -- industry -- sales</p>
  
  <p>-a --------usa-------1----------1----------300</p>
  
  <p>-a---------usa-------2----------1--------4000</p>
  
  <p>-b---------ger-------1----------1--------200</p>
  
  <p>-b---------ger-------2----------1--------400</p>
  
  <p>-c---------usa------1----------1----------100</p>
  
  <p>-c---------usa------2----------1----------300</p>
  
  <p>-d---------usa------1----------1----------400</p>
  
  <p>-d---------usa------2----------1----------200</p>
  
  <p>-e---------usa------1----------1----------7000</p>
  
  <p>-e---------usa------2----------1----------900</p>
  
  <p>-f----------ger------1----------2----------100</p>
  
  <p>-f---------ger------2----------2----------700</p>
  
  <p>-h---------ger------1----------2----------700</p>
  
  <p>-h---------ger------2----------2----------600</p>
  
  <p>-.................etc.....................................</p>
  
  <p>I tried the programing you mentioned, but I got a couple of variables that need to be used in the same row and not in the same column (which I would probably need). Is there a possibility to keep the data without reshaping, keeping them in a row, for example grouping the observations:</p>
  
  <p><code>egen group=group(industry year country)</code></p>
  
  <p>and then try</p>
  
  <p><code>xtset group year
  bysort group: sales_growth = log(D.sales)</code>
  or
  <code>bysort group: gen sales_growth = (sales[_n]-sales[_n-1])/sales[_n-1]</code></p>
  
  <p>Thank you!</p>