A problem with #15 is that second time around the loop the variable already exists and you can't generate it again.
Another problem is the misuse of inrange(). Also, to test for equality you need == not =.
I don't know why +1 appears any way -- or why you have 8 high values and 9 low values.
This should get you closer:
But all you want here is 10-year bins.
gets you there in one. Also, your bins are then self-describing, as lower limits 0, 10, 20, ..., ...
Another problem is the misuse of inrange(). Also, to test for equality you need == not =.
I don't know why +1 appears any way -- or why you have 8 high values and 9 low values.
This should get you closer:
Code:
gen gr = . local HI 9 19 29 39 49 59 69 79 . local this = 1 forval lo = 0(10)80 { gettoken hi HI : HI replace gr = `this' if inrange ( age, `lo', `hi') local ++this }
Code:
gen gr = 10 * floor(age/10)
Comment