Dear Statalist,
I have encountered a seemly simple question when I was trying to "forvalues" in STATA 15.
Before the forvalues, the codes were: (which works without any error)
Then, I tried to use "forvalues" to simplify my codes:
And STATA log showed that:
i not found
r(111);
Anyone has a thought about that? Really don't know what is going wrong here...though it really seems a simple loop for me
Any reply would be very much appreciated! Thanks in advance!
Yingyi
I have encountered a seemly simple question when I was trying to "forvalues" in STATA 15.
Before the forvalues, the codes were: (which works without any error)
Code:
generate new_var=old_var + 1 if inrange(_n,(1-1)*5760+1,5760*1) replace new_var=old_var + 2 if inrange(_n,(2-1)*5760+1,5760*2) replace new_var=old_var + 3 if inrange(_n,(3-1)*5760+1,5760*3) replace new_var=old_var + 4 if inrange(_n,(4-1)*5760+1,5760*4) replace new_var=old_var + 5 if inrange(_n,(5-1)*5760+1,5760*5) replace new_var=old_var + 6 if inrange(_n,(6-1)*5760+1,5760*6) replace new_var=old_var + 7 if inrange(_n,(7-1)*5760+1,5760*7)
Code:
forvalues i=1(1)7{ gen neww_var=old_var + i if inrange(new_n,(i-1)*5760+1,5760*i) format loop_date %tdNN/DD/CCYY }
i not found
r(111);
Anyone has a thought about that? Really don't know what is going wrong here...though it really seems a simple loop for me

Any reply would be very much appreciated! Thanks in advance!

Yingyi
Comment