Dear All,

I am using stata 15 under windows 10

At the moment I am working with a panel dataset (with missing values) unbalanced panel, which is defined as follows

egen company = group(Companynumber)
xtset company year, yearly


I want to calculate the moving average for the sales growth of the last 3 years for each industry.

Here is my code
1.
sort company year
bys company: gen salesgrowth = (SALES-L1.SALES)/L1.SALES


2.
bysort industry year : egen TOTALGROWTH_INDUSTRY = total(salesgrowth)

sort industry year TOTALGROWTH_INDUSTRY

rangestat (mean) TOTALGROWTH_INDUSTRY, interval(year -3 -1) by(industry)

For example in 2011 the average growth from 2008-2011 should be shown.

Unfortunately, my values for rangestat are not correct.
I have checked it a few times with a calculator and I calculated other values than rangestat.

Maybe you have some advice for me