Consider the following toy example:
clear
set obs 1
forvalues i = 1 / 3 {
generate x`i' = runiform()
}
list
+--------------------------------+
| x1 x2 x3 |
|--------------------------------|
1. | .3913819 .1196613 .7542434 |
+--------------------------------+
Here's one way to do what you want:
local varlist1 "x1 x2 x3"
local varlist2 "a b c"
tokenize `varlist2'
local i 0
foreach var1 of local varlist1 {
local ++i
rename `var1' ``i''
}
list
+--------------------------------+
| a b c |
|--------------------------------|
1. | .5844658 .3697791 .8506309 |
+--------------------------------+
The idea here is to break up the local macro varlist2 in separate arguments 1, 2, 3 etc. and then move through them using a counter local macro i.
Alternatively, you can simply do:
local varlist1 "x1 x2 x3"
local varlist2 "a b c"
rename (`varlist1') (`varlist2')
or:
rename x# (`varlist2')
foreach i of local varlist1 & j of local varlist2but the form is still ambiguous whether you want all possible pairs or parallel loops.