| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: re counting missing
Hello Svend,
your code is much shorter than mine! But it will not work in that very
special case, when none of the observations of a certain class is in the
dataset.
Look at the original dataset fragment, posted by Richard. There are
observations of classes: "Normal", "synchronous", "High amplitude" and
"Failure". But according to the question, there are 5 different classes
(whatever the classes mean). -fillin- will not know anything about it.
As a work-around one might create a fictious observation (new id) containing
all 5 classes, then run your code, then delete it.
Best regards,
Sergiy
----- Original Message -----
From: "Svend Juul" <[email protected]>
To: <[email protected]>
Sent: Friday, February 23, 2007 10:52 AM
Subject: Re: st: re counting missing
--------------------------------------------------------------------------------
From "Richard Hiscock" <[email protected]>
To <[email protected]>
Subject st: re counting missing
Date Fri, 23 Feb 2007 18:03:19 +1100
--------------------------------------------------------------------------------
Richard Hiscock wrote:
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.
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.
-------------------------------------------------
-fillin- is useful for your problem:
clear
input id class5 number
1 2 12
1 3 6
1 4 2
2 1 3
2 2 1
2 5 8
end
fillin id class5
recode number(.=0)
drop _fillin
by id, sort: egen t=total(number)
gen proportion=number/t
list
+--------------------------------------+
| id class5 number t propor~n |
|--------------------------------------|
1. | 1 1 0 20 0 |
2. | 1 2 12 20 .6 |
3. | 1 3 6 20 .3 |
4. | 1 4 2 20 .1 |
5. | 1 5 0 20 0 |
|--------------------------------------|
6. | 2 1 3 12 .25 |
7. | 2 2 1 12 .0833333 |
8. | 2 3 0 12 0 |
9. | 2 4 0 12 0 |
10. | 2 5 8 12 .6666667 |
+--------------------------------------+
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, work: +45 8942 6090
Phone, home: +45 8693 7796
Fax: +45 8613 1580
E-mail: [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/
*
* 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/