Statalist The Stata Listserver


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

st: Re: excluding variables from varlist


From   n j cox <[email protected]>
To   [email protected]
Subject   st: Re: excluding variables from varlist
Date   Fri, 26 May 2006 16:09:47 +0100

This works, but it is rather a roundabout solution,
with some disadvantages.

local vl "`vl' `v'"

is better in a loop than

local vl = "`vl' `v'"

as the latter can hit limits on length of expressions
and give rise to bugs.

When it is necessary to unpack a varlist into
discrete items, the most direct approach is not
a loop but

unab varlist : _all

or

unab varlist : *

However, note that these macros will include the
names of any temporary variables in existence. If
it were needed, I guess that the most direct way
to gather names of temporary variables would be

unab temp : __*

where the underscore is doubled. This is based
on the assumption that no permanent variable
has a name starting with an underscore.

I follow Phil Schumm in preferring something like

unab varlist : _all
unab exclude : <whatever>
local varlist : list varlist - exclude

-ds <whatever>, not- gets you to the same place, more
or less, but with more interpretative overload.

Nick
[email protected]


Doug Owens

Another solution I sometimes use is of the form:

sysuse auto, clear
foreach var of varlist _all {
   local vl = "`vl' `var'"
}

local exclude "trunk weight disp length mpg make"
local vl: list vl - exclude
di "`vl'"



local

> 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 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index