My job is to sum the amount of items each group has, my data looks like this in long data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(group id) str9 firstname str8 lastname str2 item1 float count_1 str2 item2 float count2 1 1 "bob" "jones" "A" 20 "B" 1 1 2 "sean" "smith" "F" 10 "A" 5 2 1 "peter" "joe" "OO" 100 "AC" 20 2 2 "lily" "milner" "AB" 10 "OO" 100 2 3 "yusef" "notib" "OO" 14 "AB" 4 end
Here is code for wide "reshape wide firstname lastname item* count*, j(id) i(group)"
Code:
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | group firstn~1 lastna~1 item11 count_11 item21 count21 firstn~2 lastna~2 item12 count_12 item22 count22 firstn~3 lastna~3 item13 count_13 item23 count23 | |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 1. | 1 bob jones A 20 B 1 sean smith F 10 A 5 . . | 2. | 2 peter joe OO 100 AC 20 lily milner AB 10 OO 100 yusef notib OO 14 AB 4 | +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
My goal is to collapse my data by group, such that group 1 would have the items across individual 1 and 2 summed together... Any advice?
0 Response to Sum individuals' totals into a group sum?
Post a Comment