title: Calculating year dummy variables using a for loop (foreach) in Stata
body: <p>I am attempting to generate a dummy variable for each year from 1996 to 2012 (inclusive) such that the 1996 dummy should equal 1 if it is 1996 and 0 if else using the <code>foreach</code> command in Stata to cut down on time (at least for future projects). What is currently happening is that the dummy for 1996 is being produced, but no others are generated. 
  I think that it has to do with how I am defining <code>j</code>, but I cannot quite figure out the formatting to achieve the results that I want. I have looked online and in the Stata help files and cannot find anything on this specific topic.</p>
  
  <p>Here is what I have thus far:</p>
  
  <pre><code>local var year
  local j = 1996
  foreach j of var year {
      gen d`j' = 1 if year==`j'
      local ++j
  }
  </code></pre>
  
  <p>I will continue to try and figure this out on my own, but if anyone has a suggestion I would be greatly appreciative.</p>