Dear statalisters,
Below is an illustration of my data structure. I want to total segsales for each year, segsic, combination , but only for observations that have priseg =1 (a flag),
e.g. for year 1999, I expect totalsale = 20 + 25+50 (since firm 1001, 1002, 1003 share the same 4100 in year 1999).
For year 2000, I expect totalsale for 4200 segsic=21+22, and totalsale for 4300 segsic=33
input firmid year segsales segsic priseg
1001 1999 20 4100 1
1001 1999 10 4200 0
1001 1999 . 5100 .
1002 1999 25 4100 1
1002 1999 15 5100 0
1003 1999 50 4100 1
1003 1999 31 4200 0
1001 2000 19 4100 0
1001 2000 21 4200 1
1001 2000 . 5100 .
1002 2000 22 4200 1
1002 2000 13 5100 0
1003 2000 33 4300 1
end
I am not sure if I need generate another variable using something like egen group (segsic priseg) to flag my observations.
Thank you,
Rochelle
Below is an illustration of my data structure. I want to total segsales for each year, segsic, combination , but only for observations that have priseg =1 (a flag),
e.g. for year 1999, I expect totalsale = 20 + 25+50 (since firm 1001, 1002, 1003 share the same 4100 in year 1999).
For year 2000, I expect totalsale for 4200 segsic=21+22, and totalsale for 4300 segsic=33
input firmid year segsales segsic priseg
1001 1999 20 4100 1
1001 1999 10 4200 0
1001 1999 . 5100 .
1002 1999 25 4100 1
1002 1999 15 5100 0
1003 1999 50 4100 1
1003 1999 31 4200 0
1001 2000 19 4100 0
1001 2000 21 4200 1
1001 2000 . 5100 .
1002 2000 22 4200 1
1002 2000 13 5100 0
1003 2000 33 4300 1
end
I am not sure if I need generate another variable using something like egen group (segsic priseg) to flag my observations.
Thank you,
Rochelle
Comment