I need to merge two different datasets. In one dataset, there is a variable called “Dyadpair” which contains a number that represents two different country codes. For example, the Dyadpair “2365” represents the United States (2) and Russia (365).
In my second dataset, there is not a “Dyadpair” variable…but I need to create one so that I can merge these two datasets.
In this second dataset, I have a variable called “stateA” (to represent the attacker state) and a variable called “stateB” (to represent the victim state). These states are in the same country code format of my first dataset (e.g. “2” to represent” the United States). However, I am working with 3858 observations, so there are a number of different country codes.
Considering “stateA” (attacker state), the country codes range from “2” to “940.” Considering “stateB” (victim state), the country codes range from “2” to “986.”
I need to combine “stateA” with “stateB” to get a new “Dyadpair” variable - in such a way where the smaller country code appears first (so it matches the first dataset). But I need this variable to stay in that dataset (not appear as a data frame), because I am not finished working with this dataset. (Next, I will need to aggregate the # of attacks per year, based on each “Dyadpair”).
Here is what my dataset looks like (well, it doesn't yet have the variable "dyadpair" - that is what I would like for it to look like):
       incidentnumber   stateA  stateB   year    actiondummy   dyadpair
1      3551005          211     345      1992    1             211345
2      3551002          20      200      1992    1             20200         
3      3551003          390     360      1992    1             360390 
4      3551004          220     2        1992    1             2220   
5      3551005          255     645      1992    1             255645
6      3551006          350     690      1992    1             350690
7161   4598003          770     2        1992    0             2770 
7163   4599001          700     630      1992    0             630700
7164   4599002          700     630      1992    1             630700
I would like to create a new variable called "dyadpair" - which combines "stateA" with "stateB" ... but it is very important that the smaller country code comes first.
 
     
     
    