title: Use Stata to generate new variable, based on combination types of variables
body: <p>Say I have a dataset with three variables <code>a</code>, <code>b</code>, <code>c</code>, and having 5 observations. Like the following:</p>
  
  <pre><code>    a   b   c
      1   0   1
      1   1   1
      0   1   0
      0   1   1
      1   0   0
  </code></pre>
  
  <p>Now I want to generate a new variable called <code>type</code>, which is a possible combination of variable <code>a</code>, <code>b</code> and <code>c</code>. Specifically,  </p>
  
  <ul>
  <li><code>type=1</code> if <code>a=b=c=0</code></li>
  <li><code>type=2</code> if <code>a=c=0 &amp; b=1</code></li>
  <li><code>type=3</code> if <code>a=b=0 &amp; c=1</code></li>
  <li><code>type=4</code> if <code>a=0 &amp; b=c=1</code></li>
  <li><code>type=5</code> if <code>a=1 &amp; b=c=0</code></li>
  <li><code>type=6</code> if <code>a=b=1 &amp; c=0</code></li>
  <li><code>type=7</code> if <code>a=c=1 &amp; b=0</code></li>
  <li><code>type=8</code> if <code>a=b=c=1</code></li>
  </ul>
  
  <p>The new dataset I want to get is:</p>
  
  <pre><code>    a   b   c   type
      1   0   1   7
      1   1   1   8
      0   1   0   2
      0   1   1   4
      1   0   0   5
  </code></pre>
  
  <p>Are there any general ways to realize this in Stata? It's better if this can also be extended when <code>type</code> is large, say 100 types. Thx a lot.</p>