# sales growth-rate with multiple groups-conditions

#### Franz

##### New Member
Cross-posting @ http://stackoverflow.com/questions/17748340/stata-sales-growth-rate-of-multiple-groups?noredirect=1#comment26020905_17748340

@ german: ="http://www.stata-forum.de/post1716.html#p1716"

I want to calculate the annual sales growth rate of different firm-groups in Stata. The firms are grouped by variables: country and industry.

I summed sales for each group (called it sales_total: sales of all firms in a group with equal country, industry and year):

bysort country year industry: egen sales_total = sum(sales)

and grouped each combination:

egen group = group(year country industry)

I attached a photo with a small example of my observations (I normally have about 10.000 firms in a 10 year span).

I tried multiple combinations such as:

egen group = group(year country industry)
xtset group year, yearly
bys group: g salesgrowth = log(D.sales_total)
or

bysort group: gen salesgrowth=(sales[_n]-sales[_n-1])/sales[_n-1]
also with tsset,

to calculcate the growth, but I always get error messages such as

repeated time values within panel

or

repeated time values within sample
due to the repetition of the number in the group variable.

Can you help me find the yearly growth rate from each group (firms from same country & industry)?

Last edited:

#### bukharin

##### RoboStataRaptor
If I understand the problem correctly, you don't actually need firm-level information - just firm-groups. So I would start with:
Code:
collapse (sum) sales, by(year country industry)
You also need to decide whether your panels should be firm-groups or countries - you have to choose one (although you could combine them using -egen group=group(industry country)-)

After that it should be simple to -xtset- your data.

#### Franz

##### New Member
If I understand the problem correctly, you don't actually need firm-level information - just firm-groups. So I would start with:
Code:
collapse (sum) sales, by(year country industry)
You also need to decide whether your panels should be firm-groups or countries - you have to choose one (although you could combine them using -egen group=group(industry country)-)

After that it should be simple to -xtset- your data.
Thanks first of all bukharin.

You understood it correctly. I don't really need the firms. I just have about 10,000 firms over a 10-year span (some data such as sales or industry-group is missing for some of the firms).

Is there another solution without collapsing the rest of the data? I have about 50 other variable on the panel that should stay, if possible.

If not: I tried the programing you mentioned:
Code:
collapse (sum) sales, by(year country industry)
egen group = group(industry country)
xtset group year
bysort group: gen sales_growth = (sales[_n]-sales[_n-1])/sales[_n-1]
and it worked.

bysort group: gen sales_growth = (sales[_n]-sales[_n-1])/sales[_n-1]
bysort group: sales_growth = log(D.sales)