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

st: RE: RE: Spilt a variable into several parts


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Spilt a variable into several parts
Date   Tue, 1 Apr 2003 17:21:11 +0100

Kate

> Thanks to everybody for solutions. The one from
> Shannon and Nick was most efficient. One last issue,
> though, is that a value is assigned even when the
> original string variable is missing. Fixed this with a
> regular old _for_. Or is there a more elegant
> solution? Forgot to mention, I'm still using version 7
> but all y'all seem to have figured that out.

Setting aside the last part of this, which raises the comment
"That's authentic frontier gibberish!" (Olsen Johnson, Blazing
Saddles),
my answer is the same for 7 or 8:

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

That right-hand side -- which may get mailer-mangled --
is

cond(missing(procedure),.,index(procedure,"0`i'")>0)

and breaks down like this:

if missing(procedure), then value is . (numeric missing);
otherwise value is index(procedure, "0`i'") > 0

where

index(procedure, "0`i'") > 0

evaluates to 1 or 0 as usual
(http://www.stata.com/support/faqs/data/trueorfalse.html).

Nick
[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