Cathy wrote:
I have a dataset with hospital and ICU data.
I'd like to replace missing data for one ICU
with the average value of the other 3 icu's at
that hospital. The dataset looks like this:
Unit_ID Total_Score
11 .
12 90
13 60
14 27
I can get the average for total score for the 3 units
by using "if" and specifying the unit id's. But how
can I then replace the missing unit's score with the
average from the 3 other units?
-----------------------------------------------
I don't know what ICU is, but that is probably not important.
Read Maarten's important comment. Assuming that you
want to do it anyway, and assuming that you have more
than one hospital, you could:
Hospital Unit_ID Total_Score
1 11 .
1 12 90
1 13 60
1 14 27
2 23 41
2 24 .
2 24 73
sort Hospital
by Hospital: egen Total_Score2=mean(Total_Score)
replace Total_Score2=Total_Score if Total_Score<.
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/