I want to generate a variable that is the sum of "trade-share of GDP" in a given year for a given country. I have data for 4 years, and I have a variable that is the "trade value" for each country pair.
Ignoring that I need to convert tradevalue and GDPimport to the same dollar amount (so both in billions of $), I want to create a column/variable that is the sum of the tradevalue for a country in a given year. So the new column would be like this:
So tradevalue is 3712 (567+789+125) for CAN in 1970, but is 3367 (2689+678) in 1972. So basically, I want to sum tradevalue by year and importer, so that the value repeats for importer in the year 1970. As you can see if have CAN twice here, once for 1970 and 1972. In my real data, I have every country in the world as both importer and exporter, so I don't want to simply add tradevalue by importer, as this would add for all four years. And since I have every country in the world, I cannot select each country.
I'm hoping to take that Tradesum value and then just divide by the GDPimport to get the trade share of GDP. But first I need to figure out how to get that tradesum variable to exist. Any help would be greatly appreciated.
year | importer | exporter | tradevalue | GDPimport |
1970 | CAN | USA | 2356 | 65748 |
1970 | CAN | AUS | 567 | 65748 |
1970 | CAN | GBR | 789 | 65748 |
1971 | IND | CHN | 125 | 46783 |
1971 | IND | JAP | 1256 | 46783 |
1971 | JAP | BEN | 34 | 67890 |
1972 | JAP | BRZ | 1345 | 67890 |
1972 | EGY | JOR | 234 | 3456 |
1972 | EGY | POL | 78 | 3456 |
year | importer | exporter | tradevalue | GDPimport | tradesum |
1970 | CAN | USA | 2356 | 65748 | 3712 |
1970 | CAN | AUS | 567 | 65748 | 3712 |
1970 | CAN | GBR | 789 | 65748 | 3712 |
1971 | IND | CHN | 125 | 46783 | 1381 |
1971 | IND | JAP | 1256 | 46783 |
1381 |
1971 | JAP | BEN | 34 | 67890 |
1379 |
1972 | JAP | BRZ | 1345 | 67890 | 1379 |
1972 | CAN | USA |
2689 | 70019 | 3367 |
1972 | CAN | AUS | 678 | 70019 | 3367 |
I'm hoping to take that Tradesum value and then just divide by the GDPimport to get the trade share of GDP. But first I need to figure out how to get that tradesum variable to exist. Any help would be greatly appreciated.
Comment