Hi everyone. I have four variables in the dataset: year, groupID, personID and X. I would like to create a new variable Y such that within each year and within each group, Y equals the value of X of the other person. So Y is basically switching the values of X. I was thinking about using egen and for loop. Thanks!
year groupID personID X Y
2005 100 1 1 0
2005 100 2 0 1
2006 101 1 0 1
2006 101 2 1 0