Code:
clear all set obs 50 generate id1 = . replace id1 = 1 if _n > 0 & _n < 10 replace id1 = 2 if _n >= 10 & _n < 20 replace id1 = 3 if _n >= 20 & _n < 40 replace id1 = 4 if _n >= 40 & _n <= 50 gen id1char = . replace id1char = 1 if id1 == 1 | id1 == 3 replace id1char = 2 if id1 == 2 | id1 == 4 generate year = . replace year = 2019 if id1 == 1 | id1 == 3 replace year = 2020 if id1 == 2 | id1 == 4 generate id2 = floor((9-1+1)*runiform() + 1) gen id2char = . replace id2char = 1 if id2 == 1 | id2 == 3 | id2 == 5 | id2 == 7 | id2 == 9 replace id2char = 2 if id2 == 2 | id2 == 4 | id2 == 6 | id2 == 8 | id2 == 10 generate message = 1
If id2 appears in that year in a message with anyone else then I would like to create an id1 id2 pair.
If the pair did not message in the data then message == 0 for that pair.
I also have variables about id1 and id2 that I would like to appear in the final data. In the example I used placeholders id1char and id2char.
My current solution is a long loop that merges the data over and over again and has errors.
0 Response to Creating all matched pairs
Post a Comment