title: Running collapse command in Stata without losing key variables?
body: <p>How can I run the following consecutive <code>collapse</code> commands in Stata without losing all of my variables? </p>
  
  <p>For example, when I run:</p>
  
  <pre><code>collapse (first) Complete num_countries, by(year Region name)
  collapse (sum) Complete (first) num_countries, by(year Region)
  </code></pre>
  
  <p>I lose a variable called <code>all_m</code>, which I need for the following command:</p>
  
  <pre><code>collapse (first) all_m num_countries, by(year Region name)
  collapse (sum) all_m (first) num_countries, by(year Region)
  </code></pre>
  
  <p>I tried storing it in a <code>local</code>, but the <code>collapse</code> command wouldn't work in this case.</p>