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

Re: st: Extracting data from mixed string


From   "Steichen" <[email protected]>
To   <[email protected]>
Subject   Re: st: Extracting data from mixed string
Date   Sat, 7 Feb 2004 15:12:32 -0500

Sounds like you are running Version 7, Paul.  It requires that you
specifically declare the variable to be a string.  Try

gen str6 oral="OVYS" if index(stk,"OVYS")

Tom

----- Original Message ----- 
From: "Paul O'Brien" <[email protected]>
To: <[email protected]>
Sent: Saturday, February 07, 2004 1:45 PM
Subject: Re: st: Extracting data from mixed string


> Thanks James. Tried but:
>
> . gen oral="OVYS" if index(stk,"OVYS")
> type mismatch
>
> Paul
>
>
> On 7 Feb 2004, at 17:21, James Hesford wrote:
>
> > 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/
> >
> >
> Dr Paul O'Brien
> Westside Contraceptive Services
> Raymede Clinic, Exmoor St, London
> W10 6DZ
> 020 8962 4450 - tel
> 020 8962 4451 - fax
> 07900 495 118 - mob
>
> *
> *   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index