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" <>
To   <>
Subject   st: RE: RE: Spilt a variable into several parts
Date   Tue, 1 Apr 2003 17:21:11 +0100


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


and breaks down like this:

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


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

evaluates to 1 or 0 as usual


*   For searches and help try:

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