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, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Select a particular test |

Date |
Fri, 24 Feb 2012 08:52:22 +0000 |

At the expense of some clarity bysort pat_id: egen OK = max(max(test == "IFA", 0) - max(inlist(test, "DFA", "CULT", "BIN", 0))) This quite possibly needs too much explanation to be interesting, but 1. The outermost -max()- is an -egen- function and the inner -max(,)- are calls to the Stata-wide function with that name, 2. If -test- is ever "IFA" then max(test == "IFA", 0) is 1. Similarly with the other term. 3. So the difference is 1 if and only if the patient has had IFA but none of the other tests. Nick On Fri, Feb 24, 2012 at 12:22 AM, Nick Cox <njcoxstata@gmail.com> wrote: > bysort pat_id : egen select = total(test == "IFA") > by pat_id : egen reject = total(inlist(test, "DFA", "CULT", "BIN")) > keep if select & !reject > > Your example implies that some tests might be repeated. If there were > exact rules on such repetition then the code might be shorter; and > possibly otherwise. > > Nick > > On Thu, Feb 23, 2012 at 10:57 PM, Peci, Adriana (OAHPP) > <Adriana.Peci@oahpp.ca> wrote: > >> I have a long form database in which each patient identified by pat_id >> have up to four tests performed. >> The test names are:IFA, DFA, CULT, BIN. >> I want to select/know how many patients had IFA but not DFA, CULT, or >> BIN. >> >> Here is an improvise of my data: >> >> Pat_id Test >> 1 IFA >> 1 DFA >> 1 CULT >> 1 BIN >> 2 BIN >> 2 IFA >> 2 DFA >> 3 IFA >> 4 DFA >> 4 CULT >> 4 CULT >> * * 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/

**Follow-Ups**:**RE: st: Select a particular test***From:*Nick Cox <n.j.cox@durham.ac.uk>

**References**:**st: RE: test command for categorical variables in survey data***From:*Nanlesta Pilgrim <nanlesta@gmail.com>

**st: Select a particular test***From:*"Peci, Adriana (OAHPP)" <Adriana.Peci@oahpp.ca>

**Re: st: Select a particular test***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**st: clustering SE xtprobit and xtgee** - Next by Date:
**Re: st: RE: RE: RE: RE: RE: looping to value of a variable** - Previous by thread:
**Re: st: Select a particular test** - Next by thread:
**RE: st: Select a particular test** - Index(es):