Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Classifying Subjects, Revisited


From   Raphael Fraser <[email protected]>
To   [email protected]
Subject   st: Classifying Subjects, Revisited
Date   Mon, 24 Oct 2005 12:58:35 -0500

Dear All,

I wish to classify the subjects of the data below. t1, t2 and t3 can
only take on the values 0 (-ve result), 1, 2, 3, 4 or 9 and represents
the results of test done. The variable ct indicates the number of
consecutive results starting from t1. I would like to classify these
subjects based on the criteria below:

"Minimal" (deg=1) if  test result is 9 or less, observed on at least
two of the three test.
"Sustained" (deg=2) if the result is minimal and lasts 3 years or more.
"Heavy" (deg=3) if sustained with results  2 or greater lasting 3 years or more.

I have attempted to classify the minimal group with the following code
which is incomplete. There are 5 objects (not counting 0) of which I
can choose two at a time (5x4=20 permutations) I realized that from
here on, classification of the other subjects would involve lots of
permutations. Is there an alternative solution to this problem? Or, is
there an easier way?

gen deg=.
if (ct==2 & geno==2){
	replace deg=1 if (t1==9 & t2==9)| ///
				  (t1==9 & t2==1)| ///
				  (t1==9 & t2==2)| ///
				  (t1==9 & t2==3)| ///
				  (t1==9 & t2==4)| ///
				  (t1==1 & t2==1)| ///
				  (t1==1 & t2==2)| ///
                                  (t1==1 & t2==3)| ///
                                  (t1==1 & t2==4)
                                   etc ... up to 20 permutations
	}
else if (ct==3 & geno==2){
	replace deg=1 if (t1==9 & t2==9)| ///
				  (t1==9 & t2==1)| ///
				  (t1==9 & t2==2)| ///
				  (t1==9 & t2==3)| ///
				  (t1==9 & t2==4)| ///
				  (t1==1 & t2==1)| ///
                                 (t1==1 & t2==2)| ///
                                 (t1==1 & t2==3)| ///
                                 (t1==1 & t2==4)
                                     ....
	                         (t1==9 & t3==9)| ///
				  (t1==9 & t3==1)| ///
				  (t1==9 & t3==2)| ///
				  (t1==9 & t3==3)| ///
				  (t1==9 & t3==4)| ///
				  (t1==1 & t3==1)| ///
                                  (t1==1 & t3==2)| ///
                                  (t1==1 & t3==3)| ///
                                  (t1==1 & t3==4)| ///
				  (t3==9 & t2==9)| ///
				  (t3==9 & t2==1)| ///
				  (t3==9 & t2==2)| ///
				  (t3==9 & t2==3)| ///
				  (t3==9 & t2==4)| ///
				  (t3==1 & t2==1)| ///
				  (t3==1 & t2==2)| ///
				  (t3==1 & t2==3)| ///
				  (t3==1 & t2==4)| ///
                                   etc ...
	}
bysort id: egen class=max(deg)

DATA
  ct   geno     id   _spell   t1   t2   t3
     2      1     31        1    9    0    9
     2      1     31        1    0    9    9
     3      1     31        2    9    9    9
     3      1     31        2    9    9    0
     3      1     31        2    9    0    9
     4      1     31        3    0    9    0
     4      1     31        3    9    0    1
     4      1     31        3    0    1    .
     4      1     31        3    1    .    .
     4      1     37        1    1    0    0
     4      1     37        1    0    0    9
     4      1     37        1    0    9    9
     4      1     37        1    9    9    1
     6      1     37        2    9    1    0
     6      1     37        2    1    0    0
     6      1     37        2    0    0    0
     6      1     37        2    0    0    0
     6      1     37        2    0    0    .
     6      1     37        2    0    .    .
     2      2     40        1    0    0    .
     2      2     40        1    0    .    .
     2      2     46        1    0    0    0
     2      2     46        1    0    0    0
     2      2     46        2    0    0    .
     2      2     46        2    0    .    .

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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index