Dear Statalisters,
I am new to Stata and have been trying to generate the following variable.

Variable Definition: ten-year sum (from t-9 to year t) of net income divided by the ten-year sum of cost of goods sold less SG&A. The variable must be between 0 and 1

This is the code I have:
Code:
sort gvkey fyear
ssc install asrol
bys gvkey: asrol ni, gen(ni_sum) window (fyear 10) stat(sum)
gen cogs2=cogs-sga
bys gvkey: asrol cogs2, gen(cogs_sum) window (fyear 10) stat(sum)
gen ni_t10=ni/cogs_sum
drop if ni>1
drop if ni_t10<0
The issue I am facing is that asrol takes a cumulative value, while all observations should have the 10-year sum. Is there a more efficient way to perform this in Stata?