| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: re counting missing
Hello Richard,
first thing that comes into my mind (not quite a ready program, but quite
straightforward):
1. create a small file with a single variable listing all possible class5
categories
2. -contract- your data to keep only unique ids
3. -cross- the two datasets. This will create all pairwise combinations of
id and class5
4. -merge- this dataset with the original data by id and class5. you will
have missings in t and number for some combinations
5. -sort- by id and t.
6. Now go with -by(id)- and -replace- number=0 if t==.
7. Go by(id) again and replace t=t[1]
Be sure not to switch steps 6 and 7
8. -gen- proportion=number/t
You might need to sort your data appropriately before merging if Stata
complains.
Surely this can be done more efficiently.
Best regards,
Sergiy
----- Original Message -----
From: "Richard Hiscock" <[email protected]>
To: <[email protected]>
Sent: Friday, February 23, 2007 8:03 AM
Subject: st: re counting missing
In study of swallowing I have oesophageal pressures measured many times
on each patient and within patients these are
coded into one of 5 contraction types. Subjects may have none up to all of
the types of contraction & many or no pressures
measured for each type.
I wish to count the number of pressures readings measured for each type
of contraction for each patient.
I have achieved this by (may be a bit long handed)
by id class5: gen n =_n
by id class5: gen number =_N
by id: gen t=_N
drop if n < number
gen proportion = number/t
format proportion %9.2f
list id group class5 t n number proportion if id <3
+--------------------------------------------------------+
| id group class5 t number propor~n |
|--------------------------------------------------------|
1. | 1 reflux Normal 20 12 0.60 |
2. | 1 reflux synchronous 20 6 0.30 |
3. | 1 reflux High amplitude 20 2 0.10 |
4. | 2 reflux synchronous 12 3 0.25 |
5. | 2 reflux High amplitude 12 1 0.08 |
6. | 2 reflux Failure 12 8 0.67 |
In examining the data I wish to look at the distribution of proportion
within each class5 category. To do this I need
to record zero in the proportions for class5 categories that did not occur
within a subject. For example for subject id 2
+--------------------------------------------------------+
| id group class5 t number propor~n |
|--------------------------------------------------------|
| 2 reflux Normal 12 0 0 |
| 2 reflux synchronous 12 3 0.25 |
| 2 reflux High amplitude 12 1 0.08 |
| 2 reflux Failure 12 8 0.67 |
| 2 reflux Ineffective 12 0 0 |
I am unable to achieve this.
Any help would be greatly appreciated.
Richard Hiscock
*
* 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/
*
* 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/