title: Stata: Generating variables in a loop using tuples local macro
body: <p>I need to generate all possible tuples of the integer numbers 1,2,3,4 (with exactly 2 items in each tuple).Then, I need to <code>generate</code> a set of variables that would correspond to the resulting six tuples. Each variable name should contain a reference to a tuple and the value of each variable should be a string version of a tuple itself, as illustrated below: </p>
  
  <pre><code>+--------+--------+--------+--------+--------+--------+
  | var_12 | var_13 | var_14 | var_23 | var_24 | var_34 |
  +--------+--------+--------+--------+--------+--------+
  |     12 |     13 |     14 |     23 |     24 |     34 |
  +--------+--------+--------+--------+--------+--------+
  </code></pre>
  
  <p>While the tuples are generated by using the <code>tuples</code> user-written command (for details, see <a href="http://ideas.repec.org/c/boc/bocode/s456797.html" rel="nofollow">http://ideas.repec.org/c/boc/bocode/s456797.html</a>), I am stumbling with generating new variables and assigning values to them in a loop. The code looks as follows and results in a syntax error which presumably stems from using local tuples macros incorrectly, and I would greatly appreciate if someone could help me solving it.</p>
  
  <pre><code>tuples 1 2 3 4, display min(2) max(2)
  
  forval i = 1/`ntuples' {
      gen v`i'=`tuple`i''  
      rename v`i' var_`tuple`i''
  }
  </code></pre>