Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: findname any of


From   Jakob Petersen <jpeterb@essex.ac.uk>
To   statalist@hsphsun2.harvard.edu
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index