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]

RE: st: RE: findname any of


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: RE: findname any of
Date   Mon, 3 Oct 2011 14:38:59 +0100

It can be simpler than that: 

isvar guitar make 
findname `r(varlist)' 

-isvar- filters out (and displays) the bad names. 

The middle macro -varlist- is not needed at all. 

Nick 
[email protected] 


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

Thanks to Jesper and Nick

A two-step solution could be:

* A *************************************
sysuse auto,clear
cap n findname make, type(string)
local varlist `r(varlist)'
di "`varlist'"
isvar guitar make
local varlist `r(varlist)'
di "`varlist'"
cap n findname `varlist', type(string)
local varlist `r(varlist)'
di "`varlist'"
**************************************

Jakob

On 03/10/2011 14:12, Nick Cox wrote:
> 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