title: How to create a variable based on a group variable, ranking variable and a value variable in stata
body: <p>I have a group variable, A, within group ranking variable, B, and a value variable, C. I need to create a new variable, D, for each group, based on the value of variable C when the within group ranking variable B has a value of one. The programming language is Stata. The desirable output for D should look like below.</p>
  
  <pre><code>A        B         C          D
  Ryan     1         1          1
  Ryan     2         0          1
  Meg      1         0          0
  Meg      2         1          0
  </code></pre>