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


From   "Jesper Lindhardsen" <JESLIN01@geh.regionh.dk>
To   <statalist@hsphsun2.harvard.edu>
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: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Jakob
Petersen
Sent: 03 October 2011 14:48
To: statalist@hsphsun2.harvard.edu
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index