id
and time identifier is year
. The asrol code you would use is given below.
bysort id : asrol ebitda, gen(sd_ebitda) stat(sd) window(year 4) min(4)The min(4) option ensures that at least 4 observations are available for the calculation of the standard deviation.