I'm trying to write code with some loops where do some data manipulations based on a window. I have trouble getting the code to a point where I just have to change a local with the window length. This works:
but the following doesn't (you can continue directly with the code). I tried display `min' and the locals are built correctly. Why does Stata not understand these as numbers? I'm a bit dumbfounded.
In my intuition, all I did was replacing a -5 with a local that is -5. What am I missing?
Code:
sysuse auto, clear
xtset price turn /*just to make sure the format fits, these arent panel variables*/
egen placeholder=mean(turn)
gen basis=round(placeholder) /*a hint how to do this in one line would also be nice ;-) */
drop placeholder
gen keeper=.
forval t = -5/6{
replace keeper=1 if turn==basis+`t'
}
Code:
replace keeper=.
local window 5
local min `window'*-1
local max `window'+1
forval t = `min'/`max'{
replace keeper=1 if turn==basis+`t'
}


Comment