Hi, I am writing a loop that looks like this

foreach code of numlist 1/202{
forvalues i=1940/2020{
forvalues j=0/4{
summ y`i'q`j' if id==`code' & inlist(indicatorcode,"A", "B", "C", "D")
replace y`i'q`j'=r(sum) in 2*`code'-406
summ y`i'q`j' if id==`code' & inlist(indicatorcode,"X", "Y", "Z")
replace y`i'q`j'=r(sum) in 2*`code'-405
}
}
}

There is a problem with the replace command as STATA can't understand 2*`code'-406 where it is written. How do I make this work?

So essentially, when writing a command
replace newvar = exp in #
how can I make # into a function using a variable from foreach?