I'm using Stata 13.1 in Windows 7

Is there any way to calculate the average of sales (

**sale**) growth for the five years prior to the focal year (

**fyear**) for each sector (

**sic**), which includes all firms (

**gvkey**) in this sector?

I'm using the natural log of sales rather than raw sales

I used the following codes:

Code:

sort gvkey fyear bys gvkey: gen logsale= ln(sale) bys gvkey: gen salegrow = (logsale-L.logsale)/L.logsale bysort sic fyear: egen sum = sum(salegrow) bys sic fyear: egen avrg = filter(sum), coef(1 1 1 1 1) lags(-1/-5) normalise

I also tried:

Code:

bys sic fyear: gen avrg= mean(L.sum + L2.sum + L3.sum + L4.sum + L5.sum) and bys sic fyear: gen avrg= sum(L.sum + L2.sum + L3.sum + L4.sum + L5.sum)/5

Many thanks in advance

## Leave a comment: