Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: RE: a question on how to create a complex loop

 From Reinhardt Jan Dietrich To "statalist@hsphsun2.harvard.edu" Subject st: RE: a question on how to create a complex loop Date Wed, 8 Feb 2012 16:22:24 +0000

```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.

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/
```