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 on April 23, and its replacement, 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   Rebecca Pope <>
Subject   Re: st: drop range of variables meeting condition in another variable
Date   Mon, 18 Mar 2013 21:14:17 -0500

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

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