I would appreciate any pointers on how to get this loop to work. After
using insheet I have variables named var3, var4, var5...var14 which
correspond to measurements made on day 18, 15, 12, 9, 7, 6, 5, 4, 3, 2, 1,
0 before an event. I have used the following to rename the variables,
unsuccessfully. It renames v3 to preday18, but names v4 to preday0 and
then fails on v5 with the error message "preday0 already defined. it seems
I'm losing the value of `d2' generated in the nested "foreach num" loop
when it returns to the first "foreach var" loop. perhaps it's just late,
but i can't seem to come up with a variation that works.
My construct is:
local d = 18
local d2 string(`d')
foreach var of varlist v3-v14 {
renamev `var' "preday"+ `d2'
foreach num of numlist 15 12 9 7 6 5 4 3 2 1 0 {
local d = `num'
local d2 string(`d')