Hello! I need some help with collapsing some data into groups. The variables are country1 and country2, and samegroup, which indicates if the countries are in the same group (continent). The original data I have is something like this:


China Vietnam 1
France Italy 1
Brazil Argentina 1
Argentina Brazil 1
Australia United States 0
United States Australia 0
Vietnam China 1
Vietnam Thailand 1
Thailand Vietnam 1
Italy France 1



And I would like the output to be this:


China 1
Vietnam 1
Thailand 1
Italy 2
France 2
Brazil 3
Argentina 3
Australia 4
United States 5



My first instinct would be to sort the initial data by "samegroup", then reshape (wide to long). But that doesn't quite solve the issue and I'm not sure how to continue from there. Any help would be greatly appreciated!