title: Check if variable exists in Stata
body: <p>I am looking for a way to check whether a variable exists in a Stata dataset, and if not to repeatedly check variable names over a loop until I find one that exists.  I am aware of the other responses to similar questions that involve <code>confirm</code> and depend on testing the value of <code>_rc</code>.  </p>
  
  <p>However, if you try to use these approaches repeatedly the value of <code>_rc</code> in any given iteration of a loop is only informative of whether there has been at least one error in any prior iteration.  I wish to continue testing until there is not an error, but whenever the first attempt results in an error there is no way to tell if the second attempt also results in an error because <code>_rc</code> remains the same regardless (assuming all errors report the same code).  Is there any way to either reset <code>_rc</code> to zero manually, or to test for the existence of a variable in a less ad hoc way that doesn't involve <code>_rc</code>?</p>