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 | st: RE: Patient age at first cancer exam in STATA |
Date | Sat, 11 Jan 2014 22:30:41 +0000 |
John, I think you want something like: bysort Patid Cancer: egen DateCancerDx=min(Dateexam) if Cancer==1 gen Age=(DateCancerDx-Datebirth)/365.25 This will only calculate the date of cancer diagnosis for those who actually had cancer and will calculate the earliest date from among the exams at which the patient had cancer. I am a little confused, though, by your statement that Patid 1 did not have a cancer exam, since there is a valid date value in the Dateexam variable. Did you mean to say that no cancer was diagnosed? If so, then this code should work; if not, then please clarify what the value in Dateexam refers to. Regards, Joe Canner Johns Hopkins School of Medicine ________________________________________ 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 5:08 PM To: statalist@hsphsun2.harvard.edu Subject: st: Patient age at first cancer exam in STATA Hello everybody, I’m trying to figure out a problem. I have a file with variables: 1. Patient id 2. Indication if patient suffers from cancer or not (Cancer = 1, no cancer = 0) 3. Date of birth (e.g. 23dec1955) 4. Date of medical exam (e.g. 15aug2005) I want to create a variable where I would indicate HOW OLD was the PATIENT when he received his FIRST MEDICAL EXAM and that is for CANCER. The problem is that one patient can have many exams for cancer e.g.: Patid Cancer Datebirth Dateexam 1 0 11jul1985 10aug1999 2 0 11aug1983 10aug1999 2 1 11aug1983 24jun2003 3 1 05aug1933 23aug2007 3 1 05aug1933 20aug2005 4 1 15jun1945 15jan2010 4 1 15jun1945 19feb2005 4 1 15jun1945 23dec2011 5 1 23dec1955 15aug2005 Patient 4 (patid 4) had 3 exams for cancer in 15jan2010, 19feb2005 and 23dec2011, so I just want to know his age in 2005. Another thing is that patient 1 (patid1) didn’t receive a cancer exam, so I don’t want to include his result in the variable. Can anyone help me? Maybe starpen? Kind Regards John Cybulski * * 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/