Adding across years

40 Views Asked by At

Quick question. I'm working with code that produces a spreadsheet that contains the information like the following:

year business sales profit
2001    a   5   3
2002    a   6   4
2003    a   4   2
2001    b   2   1
2002    b   6   3
2003    b   7   5

How can I get Stata to total sales and profits across years?

Thanks

1

There are 1 best solutions below

0
On

Try

collapse (sum) sales profit, by(year)

or, if you want to retain your original data,

bysort year: egen tot_sales = total(sales) 

egen stands for extended generate, a very useful command.