Good afternoon,

I am currently working on my data for my master's thesis but I am having some obstacles.
Below I provide a small sample of my dataset.
I would like to know how can I create a dummy variable that equals 1 if both contact and peer have the same sex (no matter if sex =1 or 0). In my dataset, I have 262 villages, and each of them has 4 peers and 1 contact. However, the sequence peer-contact does not follow any logic.
Village Sex What I need:
Peer 1 1 1 (since this peer and contact of village 1 has the same sex)
Peer 1 1 1
Peer 1 0 0 (since contact in village 1 has sex=1, but this peer has sex=0)
Contact 1 1 1
Peer 1 0 0
Peer 2 0 1 (since this peer and contact of village 2 has the same sex)
Contact 2 0 1
Peer 2 1 0 (since contact in village 1 has sex=0, but this peer has sex=1)
Peer 2 1 0
Peer 2 0 1
I would be so grateful if someone can help me with this. I have been struggling for a while but I haven't found the way. ( have Stata16)

Thank you in advance,
Maria