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/