Dear all
I need to take the standard deviation of every realization of annual sales growth over the past 3 years prior to year t for the firm ' i' as sales_volatilityit .
Assume Sales growth =(Salesgrowtht-Salesgrowtht-1)/Salesgrowtht-1
My question is how to generate sales_volatilityit ?

I used the following commands

**id stands for firm id**

Code:
bysort id year :gen sg= d.sales/l.sales
label var sg "sales growth"
// setting the panel//
xtset id year
ssc install tsegen
tsegen sd_sg= rowsd(L(1/3).sg)
label var sd_sg "sales_volatilityi"
Are my commands correct? Any help in this regard will be highly helpful