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: RE: findname any of


From   "Jesper Lindhardsen" <[email protected]>
To   <[email protected]>
Subject   st: RE: findname any of
Date   Mon, 3 Oct 2011 15:04:34 +0200

Hi Jakob,

I must confess I don't follow what you really want. But you might be put
off track if you think that the r(varlist) macro contains all variables
if -findname- does not find any matching variables.
In fact r(varlist) will be empty, but using -summarize- to illustrate
it, goes wrong as -summarize- lists all variables if nothing is
specified (`varlist' equlas nothing in your example).

Use -display- instead of -summarize- (display "`varlist'")

HTH, Jesper

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Jakob
Petersen
Sent: 03 October 2011 14:48
To: [email protected]
Subject: st: findname any of

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/

*
*   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