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

st: RE: grouping data


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: grouping data
Date   Thu, 27 Jun 2002 09:09:01 +0100

Rodrigo Briceņo

> I have data about discharges by service in a variable called "servicio". 
> For some reason hospital divided the Obstetrics service in those 6 groups.
> 
> HOSP. OBSTETRICIA
> HOSP. OBSTETRICIA C 
> HOSP. OBSTETRICIA P 
> HOSP. PEDIATRIA
> OBSTETRICIA C
> OBSTETRICIA P 
> 
> What can I do in order to aggrupate the 6 discharges values in a 
> unique service called Obstetrics?  I need this aggrupation in 
> order to calculate Average Lenght of Stay.


I will guess that this is a string variable. 

What unites five of these cases is the occurrence 
of "OBSTETRICIA", so one criterion to catch those is 

if index(servicio, "OBSTETRICIA") 

and for the other case a criterion is 

if servicio == "HOSP. PEDIATRIA" 

or the slightly more general 

if trim(servicio) == "HOSP. PEDIATRIA" 

So what you want might well be (all one command) 

replace servicio = "OBSTETRICIA" 
if index(servicio, "OBSTETRICIA") | 
trim(servicio) == "HOSP. PEDIATRIA" 

Here 

if index(servicio, "OBSTETRICIA") 

is short-hand for 

if index(servicio, "OBSTETRICIA") > 0 

-index()- is documented as a string function. 

The underlying principle behind that short-hand is explained at 

http://www.stata.com/support/faqs/data/trueorfalse.html

or in Stata Journal 2(1), 86-102 (2002): see Section 5
of that article. 

Nick 
n.j.cox@durham.ac.uk 

<<attachment: winmail.dat>>




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