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/