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

Re: st: Extracting data from mixed string


From   James Hesford <hesford@olin.wustl.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Extracting data from mixed string
Date   Sat, 7 Feb 2004 11:21:01 -0600

If you don't have duplicate oral contraceptives in variable, stk, a simple solution seems to be:

gen oral = "OVYS" if index(stk,"OVYS")
replace oral = "MICROG" if index(stk, "MICROG")
replace oral ="FEMOD" if index(stk, "FEMOD")
replace oral = "LOGED" if index(stk, "LOGED")

Items not have matches are blank, but you can replace this with BLANK by making this your first command (i.e., gen oral = BLANK followed by the series of replacements).


Database of 41,000 clinic visits with 26 variables for each visit. One variable is a string (stk) of contraceptives prescribed, containing 1 to 4 types, separated by commas.

stk
NONE,OVYS
NONE,NONE,NONE,MATES6,NATURAL
NONE,MICROG
NONE,NONE
NONE,FEMODE,NATURAL
NONE,NONE
LOGED
NONE,NONE,MICROG,MATES6,NATURAL
NONE
NONE,LEVONEL,MICROG
MICROG
NONE,NONE,LOG
NONE,NONE,NONE
NONE,MATES6,NATURAL
NONE,NONE
MICROG,ULTRA
NATURAL
NONE,MICROG,NATURAL

Some are oral contraceptives:OVYS MICROG FEMODE, LOGED

The position of the oral contraceptives in the string varies.

I want all the oral contraceptives in one column:

OVYS
blank
MATES6
MICROG
blank
FEMO
blank
LOGED

How?

Help gratefull received.

Paul

*
* 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/



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