Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: findname any of


From   Jakob Petersen <[email protected]>
To   [email protected]
Subject   st: findname any of
Date   Mon, 03 Oct 2011 13:48:18 +0100

Statalist

I would like to create macro lists of variables based on various conditions (Stata 11.2).

The question: Is it possible to specify –findname- to “any of” instead of “all of”?

If a variable is not found the `r(varlist)’ seems to end up listing all variable
names (same for -ds-):

*1 *************************************
sysuse auto,clear
cap n findname make
local varlist `r(varlist)'
su `varlist'
cap n findname guitar make
local varlist `r(varlist)'
su `varlist'
**************************************


I guess !_rc {} could be used to fix this:

*2 *************************************
sysuse auto,clear
cap n findname make
if !_rc {
local varlist `r(varlist)'
su `varlist'
}
cap n findname guitar make
if !_rc {
local varlist `r(varlist)'
su `varlist'
}
**************************************

-lookfor- could be an (“any of”) alternative, but is much more limited in terms of options compared to –findname-

* 3 *************************************
sysuse auto,clear
cap n lookfor make
if !_rc {
local varlist `r(varlist)'
su `varlist'
}
cap n lookfor guitar make
if !_rc {
local varlist `r(varlist)'
su `varlist'
}
**************************************

Any ideas?

Jakob Petersen

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index