Dear Mandy,
I think that trying to manipulate j within the "if" statement on your

fourth

line is causing the problem. If you first create another local macro

that's

equal to that value and include it, the loop should work correctly. See

below:

local j 0802
forvalue i=1/8 {
g age`i'=2006-T099`j'
local k = `j'-1
replace age`i'=2006-T099`j'-1 if T099`k' > 5
local j = `j' + 500
}
I am assuming that the first "T099`j'-1" in the "replace" line is
supposed to be the value of T099`j' minus 1, not the value of T099`k'
as defined here.