title: Stata Renaming Variables using first line data
body: <p>I used <code>insheet</code> to read in CSV format data. The names of the variables should be the first line of the dataset. I have a lot of variables and many years of data to read in so I would like to do this using a <code>foreach var</code> loop as follows:</p>
  
  <pre><code>   input str8 x str8 y str8 z
     first second third
     3 6 2
     4 1 2
     8 7 6
     end
  
     foreach var of varlist * {
       rename variable "`var'" "`=`var'[1]'"
     }
  </code></pre>
  
  <p>Unfortunately, I receive a <code>syntax error</code> response. </p>
  
  <p>I'm assuming the problem must be in the way I specified the new name. I was extrapolating from this Q&amp;A: <a href="http://www.stata.com/statalist/archive/2011-09/msg01109.html" rel="nofollow">http://www.stata.com/statalist/archive/2011-09/msg01109.html</a></p>