title: Stata: wildcard with exceptions in egen functions
body: <p>I am new to using macros, and I want to incorporate this <a href="http://www.stata.com/statalist/archive/2006-12/msg00911.html" rel="nofollow">"Wildcard with exceptions" syntax</a> into an <code>egen</code> function in Stata 12.  I would like to do something along the lines of this:</p>
  
  <pre><code>foreach i in E F G {
      unab all`i' : V_`i'*
      unab excl`i' : V_`i'9*
      local general`i' : list all`i' - excl`i'
  } 
  
  egen Exp_operating = rowtotal(`generalE')
  egen Exp_capital = rowtotal(`generalF' `generalG') 
  </code></pre>
  
  <p>In words, I want to make a variable list of <code>V_E*</code> that excludes variables <code>V_E9*</code>, and then create a variable that is equal to the sum of each variable in that list for each observation. However, I get a syntax error after executing the <code>egen</code> command.  Can someone help me figure out how to do what I want to do?</p>