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]

Re: st: drop range of variables meeting condition in another variable


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: drop range of variables meeting condition in another variable
Date   Tue, 19 Mar 2013 12:27:23 +0000

Thanks to Rebecca, who is entirely correct, for fielding this.

The help file does give various examples in which

`r(varlist)'

is exactly what you use after -findname- (SJ). Tamer might also like
to consult the original paper for more discussion.

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

Nick

On Tue, Mar 19, 2013 at 2:14 AM, Rebecca Pope <rebecca.a.pope@gmail.com> wrote:
> Tamer,
> You have misunderstood Nick's code. You are not meant to replace
> "varlist" in `r(varlist)' yourself. r(varlist) is a returned value of
> the program -findname-. When you type -drop `r(varlist)'- after
> -findname-, Stata will expand that local macro with the names of the
> variables that met your specified condition, all(@==0).
>
> With respect to your question about a 2nd condition, the -findname-
> help file indicates that you may specify -if- conditions. Therefore:
>
> findname gene* if case==1, all(@==0)
>
> will find variable names where the no cases have that gene cluster but
> the cluster may still exist among controls.
>
> You can see a test case using data designed to have all 0s for
> odd-numbered genes among cases only:
> **begin example **
> clear
> version 12
>
> set obs 100
> gen case = _n<=50
>
> forvalues i=1/6 {
> gen gene`i' = max(0,(-(ceil(`i'/2)-floor(`i'/2))*case)+round(runiform()))
> }
>
> findname gene*, all(@==0)
>
> findname gene* if case==1, all(@==0)
> ** end example **
>
> You'll see the 1st -findname- returns no variable names but the 2nd
> returns gene1, gene3, and gene5. With 14,000 genes, I assume that
> you'll have at least some variables that meet your criteria. However,
> you may want to use -capture drop `r(varlist)'-, just in case
> -findname- doesn't find any eligible variables.
>
> Note also that you must open your single quotations with ` not '. I
> don't know if your e-mail editor "helpfully" changed that before you
> posted or if the error exists in your code.
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index