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

Re: st: splitting columns


From   "Katsuhide Isa" <[email protected]>
To   <[email protected]>
Subject   Re: st: splitting columns
Date   Sat, 30 Nov 2002 19:38:05 +0900

To Ulrich and Nick: 

Thank you for your replys.
I tested the routines suggested, and each of them worked alright.
Especially, I found the one below given by Nick very useful.

> foreach var of varlist Q* {           
> forval i=1/7 {   
> capture assert index(string(`var'),"`i'") == 0 
> if _rc { 
> gen `var'_`i' = index(string(`var'),"`i'") ~= 0  
> } 
> }
> }

Actually, this routine is very flexible in that it can deal with 
variables containing the arbitrary number of choices, thanks to 
the statement 'capture assert index(string(`var'),"`i'") == 0'.
With this routine, I could save (possibly) hundreds of lines of 
statements required when simple 'gen [newvar] if ...'  routine is 
repeatedly employed.

K.I.


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