I have a global macro:
global global_macro sheep frog dragon
I loop over this macro and I want to be able to generate three new variables based on the current index value of global_macro
:
foreach i in $global_macro {
***define local index***
...
gen new_var_`index' = 5
}
So I want it to produce the variables new_var_1
, new_var_2
, and new_var_3
because sheep
is the first value in global_macro
, frog
is the second, and dragon
is the third. index
would first contain 1
, then 2
, and finally 3
.
I know that there is basically the opposite functionality in the extended macro function called word
. This allows one to access a value in a macro based on the index - as opposed to accessing the index based on the value.
Is there a function to do what I would like?