Attaullah Shah
Post count: 118

The code is the same as used in my earlier reply. That calculates the moving average of the last 4 years. If you want to exclude the current year, then the code would be:

bysort id : asrol ebitda, gen(sd_ebitda) stat(sd) window(year 5) min(4) xf(focal)