Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: excluding variables from varlist


From   Phil Schumm <pschumm@uchicago.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: excluding variables from varlist
Date   Wed, 24 May 2006 12:35:06 -0500

On May 24, 2006, at 11:59 AM, Thomas wrote:
using the foreach command I would like to exclude certain variables, e.g:
"foreach var of varlist _all [/excluding a, b, c/]".

Is that possible and if so how?

For maximum readability, I'd suggest the following:


unab allvars: _all
loc vars_to_exclude "a b c"
loc pruned_list : list allvars - vars_to_exclude
foreach var of loc pruned_list {
    ...
}


or, if you're counting lines, just


unab allvars: _all
loc vars_to_exclude "a b c"
foreach var in `:list allvars - vars_to_exclude' {
    ...
}


-- Phil

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index