Hey Statalisters,
after some hours of searching i did not find anything online that could solve my problem.
I am looking for some kind of "horizontal collapse".
My data looks as follows. There are various identifying variables upfront, what follows are up to ten combinations per firm of a segment code with another corresponding variable (here sic and sales). The row reports these values for 2 firms (am and tm), i.e. there are up to 20 observations per row (10* (sics + corresponding sales) for 2 firms).
I would now like to collapse the data horizontally, so that if between the combinations any sic codes are duplicates, the sales will be summarized (added on top of each other) and only one sic code plus the added sales remain. Obviously all other unique sic codes and their respective sales number should be kept the way they are. For the "collapsed" variables and the unique ones new variable combinations should be created, that show the combined firm.
The result should be something like this for the above stated example
I would be very thankful for any hints or tips!
Best regards,
Lennart
after some hours of searching i did not find anything online that could solve my problem.
I am looking for some kind of "horizontal collapse".
My data looks as follows. There are various identifying variables upfront, what follows are up to ten combinations per firm of a segment code with another corresponding variable (here sic and sales). The row reports these values for 2 firms (am and tm), i.e. there are up to 20 observations per row (10* (sics + corresponding sales) for 2 firms).
ID | am_sics1 | am_sales1 | am_sics2 | am_sales2 | tm_sics1 | tm_sales1 | tm_sics2 | tm_sales2 | ... |
1 | 11111 | 2323232 | 1213 | 12323 | 232323 | 232343 | 11111 | 434343 | ... |
2 | ... | ... | ... | ... | ... | ... | ... | ... | ... |
The result should be something like this for the above stated example
ID | new_sics1 | new_sales1 | new_sics2 | new_sales2 | new_sics3 | new_sales3 | ... |
1 | 11111 | 2757575 | 1213 | 12323 | 232323 | 232343 | ... |
2 | ... | ... | ... | ... | ... | ... | ... |
I would be very thankful for any hints or tips!
Best regards,
Lennart
Comment