Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Joe Canner <jcanner1@jhmi.edu> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | RE: Re: st: RE: Patient age at first cancer exam in STATA |
Date | Sun, 12 Jan 2014 03:48:18 +0000 |
Actually, I'm sure there are cancer patients in there, but Cancer==0 because the first record for each patient is a 0. You can solve this in one of two ways: 1. Create a variable (before the collapse) that indicates if the patient had any records with Cancer==1 bysort Patid: egen anyCancer=max(Cancer) (Come to think of it that count variable we created before can also help; it's a cancer patient if the count is greater than 0) 2.Sort the records by Patid and Cancer and take the last one instead of the first one. bysort Patid (Cancer): keep if _n==_N ________________________________________ From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] on behalf of mafotb@gmail.com [mafotb@gmail.com] Sent: Saturday, January 11, 2014 10:03 PM To: statalist@hsphsun2.harvard.edu Subject: Re: Re: st: RE: Patient age at first cancer exam in STATA Dear Joe, I have tried both: bysort Patid: keep if _n==1 and collapse. Unfortunately none of them did work. It only kept 377 unique Patid, neither of them was a cancer patient. KR John * * 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/