st: RE: Substituting string values

> -----Original Message-----
> From: Rodrigo Briceņo [mailto:rbriceno@ilapp.org]
> Sent: Monday, November 04, 2002 11:17 AM
> To: Stata
> Subject: st: Substituting string values
>
>
> Hello statalisters. I require some help: I'm working with a
> variable that is
> called "servicio". This variable has three values that
> require some fixing:
>
> 1. HOSP. OBSTETRICIA (two spaces between the words)
> 2. HOSP.OBSTETRICIA (no space between)
> 3. OBSTETRICIA C
>
> I require that these three values will be the same, for example
> HOSP. OBSTETRICIA (one single space between the two words), how can I
> substitute those values?
It is hard to know; in part it depends on whether there are additional inconsistent codes you want to regularize, or just these three. If it's these three, you can just do:
replace servicio = "HOSP. OBSTETRICIA" if servicio=="HOSP.OBSTETRICIA" | servicio=="HOSP. OBSTETRICIA" | servicio=="OBSTETRICIA C"
With more than a few, though, that would be annoying to type.
Another possibility, is to replace all cases that have the word "OBSTETRICIA" in them:
replace servicio = "HOSP. OBSTETRICIA" if index(servicio,"OBSTETRICIA")
The index() function tells you the character position that the string "OBSTETRICIA" appears in; for cases where it does not appear, the function returns zero and no change is made.
--Nick Winter
>
> Thanks.
>
> Rodrigo
>
>
> *
> * 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/