Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Lim Lee <lee.haklim@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: RE: a question on how to create a complex loop |
Date | Wed, 8 Feb 2012 18:34:24 -0500 |
another way would be to create a binary variable for each criteria then creating another variable summing the criteria by patient using egen: 1) gen "x"=1 if diag1==icd? 2) egen "y"=total(x), by(id) best, Lim On Wed, Feb 8, 2012 at 11:22 AM, Reinhardt Jan Dietrich <jan.reinhardt@paranet.ch> wrote: > You could transpose the data into wide format using reshape (type: help reshape to see the code). Then you will get diagcateg1, diagcateg2, etc., i.e. a variable for each measurement point/occasion. > Then generate a new variable > Gen diagcat_count = diagcateg1 + diagcateg2 > usw. > > Best > Jan > > > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Aluko Hope > Sent: Mittwoch, 8. Februar 2012 17:01 > To: statalist@hsphsun2.harvard.edu > Subject: st: a question on how to create a complex loop > > Dear Stata list users, > > I am a health services researcher who is relatively new to STATA and I > am trying to count the number of times each patient satisfies a > particular criteria. I think I need to do this by creating a complex > loop but I am stuck as to how to go about it. > > The data is structured in the following manner: > > id diag1 diag2 diag3 visit# diagcateg1 > 1 icd icd icd 3 1 > 1 icd icd icd 3 1 > 1 icd icd icd 3 1 > 2 icd icd icd 4 0 > 2 icd icd icd 4 0 > 2 icd icd icd 4 0 > 2 icd icd icd 4 0 > 3 icd icd icd 2 1 > 3 icd icd icd 2 1 > > the icd refer to really icd9 and the diagcateg1 is a binary variable > that already classifies certain icd9 into categories. > > in words, what i want to do now is: > whenever diagcategory is 1, count the number of times per patient (id) > that there is a diag1 diag2 or diag3 that fit a particular criteria. i > would be happy with the total number per patient but would ideally > like to be able to describe the total number per patient per visit. > > Please help, > > Many thanks in advance, > > Aluko Hope > * > * 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/ > > * > * 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/ * * 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/