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

Re: st: Spilt a variable into several parts


From   [email protected] (Shannon Driver, StataCorp)
To   [email protected]
Subject   Re: st: Spilt a variable into several parts
Date   Mon, 31 Mar 2003 16:17:09 -0600

Kate <[email protected]> wrote:

> Somebody sent me a dataset with variables like this
> one. There were 5 procedures and more than one could
> be chosen.  Instead of making each a variable, a
> single variable was made with commas separating the
> procedure number.
> 
>   procedure |      Freq.
> ------------+-----------
>    01,02,03 |         11
> 01,02,03,04 |          1
>          02 |          6
>       02,03 |        107
>    02,03,04 |         14
>       02,04 |          1
>          03 |          3
>       03,04 |          2
>          04 |          2
>          05 |          6

> I want to make 5 variables that record yes or no for
> each procedure. Index() seems to be the way to go but 
> but I don't see how to use it when there's more than
> one instance of the index character. Can somebody
> point me in the direction?

You might try something like the following:

     forvalues i = 1/5 {
          gen proc0`i' = cond(index(procedure,"0`i'"),1,0)
     }

--Shannon Driver
  [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/



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