Nada wrote:
I'm having trouble putting my finger on the solution to what may
be a simple problem.
I have a matched case control dataset with patients who have had
breast, colon or prostate cancer with 4 matched controls each and
a matching variable (groupid). My data looks like this:
id groupid breast colon prostate control
1 1 1 . . .
2 1 . . . 1
3 1 . . . 1
4 1 . . . 1
.
89 40 . 1 . .
90 40 . . . 1
91 40 . . . 1
etc
What I'm trying to do is replace breast = 0 for each control, or
colon= 0 for each control, so that my data would look like this:
id groupid breast colon prostate control
1 1 1 . . .
2 1 0 . . 1
3 1 0 . . 1
4 1 0 . . 1
.
89 40 . 1 . .
90 40 . 0 . 1
91 40 . 0 . 1
================================================================
Try this:
. sort groupid id
. by groupid: egen bmax=max(breast)
. by groupid: egen cmax=max(colon)
. by groupid: egen pmax=max(prostate)
. recode breast (.=0) if bmax==1
. recode colon (.=0) if cmax==1
. recode prostate (.=0) if pmax==1
. list id-control , clean
id groupid breast colon prostate control
1. 1 1 1 . . .
2. 2 1 0 . . 1
3. 3 1 0 . . 1
4. 4 1 0 . . 1
5. 89 40 . 1 . .
6. 90 40 . 0 . 1
7. 91 40 . 0 . 1
Hope this helps
Svend
__________________________________________
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C, Denmark
Phone: +45 8942 6090
Home: +45 8693 7796
Email: [email protected]
__________________________________________
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/