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   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: findname any of
Date   Mon, 3 Oct 2011 14:12:45 +0100

Please note that -findname- had a bug fixed in 10.4: 

SJ-10-4 dm0048_1  . . . . . . . . . . . . . . . . Software update for findname
        (help findname if installed)  . . . . . . . . . . . . . . .  N. J. Cox
        Q4/10   SJ 10(4):691
        update for not option

SJ-10-2 dm0048  . . . . . . . . . . . . . .  Speaking Stata: Finding variables
        (help findname if installed)  . . . . . . . . . . . . . . .  N. J. Cox
        Q2/10   SJ 10(2):281--296
        produces a list of variable names showing which variables
        have specific properties, such as being of string type, or
        having value labels attached, or having a date format

In respect to this example: 

sysuse auto
cap n findname guitar make
local varlist `r(varlist)'
su `varlist'

-findname- does not return a varlist in this case, so r(varlist), therefore `varlist', is empty and Stata sees -su-, and reacts accordingly.  Your interpretation of this example is thus incorrect. Nor is -ds- different in this respect. 

More crucially, what I think you want is that -findname- ignores non-variable names, at least under an option. I can see that you might want that, but I am wary of complicating a command that already seems to be too complicated to have caught on much. 

Check out -isvar- at SSC. 


Nick 
[email protected] 

Jakob Petersen

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


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