title: Stata if condition within a loop
body: <p>I am trying to write a loop with a macro variable that will change depending on the iterated value of the loop. See the code below.</p>
  <p>I want to loop over ticker values &quot;QLD&quot; and &quot;DDM&quot; and i want the local macro index to equal &quot;QQQ&quot; if the ticker is &quot;QLD&quot; otherwise &quot;DIA.&quot;</p>
  <pre><code>foreach ticker in &quot;QLD&quot; &quot;DDM&quot;{
      if `ticker'=&quot;QLD&quot;{
          local index = &quot;QQQ&quot;
      }
      else{
          local index = &quot;DIA&quot;
      }
      di `index'
  }
  </code></pre>