I am trying to compute the rolling median absolute deviation of a variable x for each group id, using 20 observations. I managed to compute the median for the rolling observations using rangestat. I then tried to use tsegen to use the egen's mad().
Create data to play with:
Compute rolling median:
Compute rolling median absolute deviation:
the last command results in an error. I fail to see how to pass the "use 20 observations" info to `mad'. Any suggestions?
(Disclaimer: Cross posted on SO: https://stackoverflow.com/questions/...lute-deviation)
Create data to play with:
Code:
clear cls set obs 100 gen id = _n expand 100 gen x = rnormal() bys id: gen time = _n
Code:
rangestat (median) x, by(id) interval(time -20 0) // this works
Code:
xtset id time tsegen mad_x = mad(L(0/20).x) // this does not work
(Disclaimer: Cross posted on SO: https://stackoverflow.com/questions/...lute-deviation)
Comment