Dear all,

Newbie question here.

Usually, I split a large variable creating new dataset for each value of this variable:

Code:
 preserve
 foreach i of num 1/8 {
         keep if BigVar == `i'
         save BigVar`i'
         restore, preserve
 }
This split BigVar in various separate datasets: BigVar1, BigVar2, etc...

Now, instead of generating a brand new dataset, I would like only to create new variables. How can I do it?

I tried

Code:
 foreach i of num 1/8 {
         if BigVar == `i'
         gen BigVar`i'
 }
But it doesn't work. I clearly don't know something very basic about STATA syntax.
Can somebody help me with that?