In a forval loop I want to reference both variable r`i'name and r`j' name, where j is a function of i.
where `j' = `i' + 1
but r`j' name invariably comes back as r[ival]+1name
specifically I run:
forval i=12(-1)1 {
local j = `i'+1
replace r`i'name = r`j'name if r`i'name_t == 0
}
and I get back a trace report that reads:
= replace r12name = r12+1name if r12name_t == 0
r12 ambiguous abbreviation
this is because I believe that Stata cannot process the relative value withing a variable name - the program does not do math in these places...
-1- is there a way for me to define both {i, j} up top - is there some way to use an ampersand or other such ting to set a counter for j along with i ahead of the open set bracket?
-2- other ideas welcome as well.
Thank you,
Jason Seligman
where `j' = `i' + 1
but r`j' name invariably comes back as r[ival]+1name
specifically I run:
forval i=12(-1)1 {
local j = `i'+1
replace r`i'name = r`j'name if r`i'name_t == 0
}
and I get back a trace report that reads:
= replace r12name = r12+1name if r12name_t == 0
r12 ambiguous abbreviation
this is because I believe that Stata cannot process the relative value withing a variable name - the program does not do math in these places...
-1- is there a way for me to define both {i, j} up top - is there some way to use an ampersand or other such ting to set a counter for j along with i ahead of the open set bracket?
-2- other ideas welcome as well.
Thank you,
Jason Seligman
Comment