Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Sergiy Radyakin <serjradyakin@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: RE: identifying observations where multiple conditions are met |
Date | Wed, 13 Nov 2013 16:03:25 -0500 |
Elizabeth, you actually don't need the "(max)" in your code, since each variable zero and one is either 1 or missing. It will not have any other value by construction. If you insist on using -collapse-, then something like this has the benefit of not being tied to particular values 0 and 1 -------------------------------------------------- clonevar t1=t clonevar t2=t sort id collapse (min) t1 (max) t2, by(id) tab id if t1!=t2 -------------------------------------------------- But collapse destroys the dataset. Sergiy Radyakin On Wed, Nov 13, 2013 at 3:49 PM, Allred, Elizabeth <lizard@hsph.harvard.edu> wrote: > Got ahead of myself! > > Collapse (max) not (sum). Sum could give you a number > 1 for both var zero and var one and then the if condition won't be met. > > gen zero=1 if type==0 > gen one=1 if type==1 > sort id > collapse (max) zero one, by(id) > l id if zero==1 & one==1 > > > > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Michael McCulloch > Sent: Wednesday, November 13, 2013 3:43 PM > To: statalist@hsphsun2.harvard.edu > Subject: Re: st: RE: identifying observations where multiple conditions are met > > Thanks Elizabeth, yes it's all -id-, where "sometimes type==0, sometimes type==1, that I'm looking for. > > The code you suggest makes sense, however at the -collapse- stage, the records disappear -id- in which the "sometimes 0 / sometimes 1" existed prior to -collapse-. > > > > Best wishes, > Michael McCulloch > > -- > Pine Street Foundation, since 1989 > 124 Pine Street | San Anselmo | California | 94960-2674 > P: (415) 407-1357 | F: (206) 338-2391 | http://www.PineStreetFoundation.org > > On Nov 13, 2013, at 12:29 PM, Allred, Elizabeth wrote: > >> On further reading, I see... You're trying to find ids with "mixed messages," i.e., sometimes 0 sometimes 1. >> >> gen zero=1 if type==0 >> gen one=1 if type==1 >> sort id >> collapse (sum) zero one, by(id) >> l id if zero==1 & one==1 >> >> -----Original Message----- >> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Michael McCulloch >> Sent: Wednesday, November 13, 2013 3:14 PM >> To: statalist@hsphsun2.harvard.edu >> Subject: st: identifying observations where multiple conditions are met >> >> Hello, >> I have data of the structure: >> id (range 1 to 300) >> type (for each -id-, should equal only one of two values: 0 or 1). >> >> In manual inspection of the data, I see instances exist where, for the same -id-, >> some records have type==0, and >> other records have type==1. >> >> If I enter >> . tab id if type==0 & type==1 >> obviously "no observations" is returned. >> >> How would I write a command in which I can tabulate all -id- for which some observations exist where type==0, and others where type==1? (At data entry, -type- should have unique for each -id-.) >> >> >> Best wishes, >> Michael McCulloch >> >> -- >> Pine Street Foundation, since 1989 >> 124 Pine Street | San Anselmo | California | 94960-2674 >> P: (415) 407-1357 | F: (206) 338-2391 | http://www.PineStreetFoundation.org >> >> >> * >> * 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/ >> >> * >> * 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/ > > > * > * 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/ > > * > * 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/ * * 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/