Hi everyone,
I have a problem here which I hope to find help for. I have a dataset of 3 vs 3 soccer matches, where each match pits teams of 3 players against another team of 3 players, who are all drawn from a pool of players. In each match, each team is assigned to either the HOME team or the AWAY team. I like to calculate for each player in each match,

A) How many times the player has played with the other players in his team as team-mates before
B) How many times the player has played with the other players in his team as opponents before
C) How many times the player has played against the other players in his opponent team as team-mates before
D) How many times the player has played against the other players in his opponent team as opponents before

The sample dataset is reproduced here, where match is the ID for each match, player is the ID for each player, and home is if the team the player is in for the match is the home team or not.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double match long player float home
1  2 0
1  1 0
1  3 0
1  4 1
1  5 1
1  6 1
2 11 0
2  1 0
2  5 0
2  3 1
2  2 1
2 12 1
3  5 0
3  1 0
3  6 0
3  7 1
3  9 1
3 10 1
4  1 0
4  2 0
4  8 0
4  4 1
4  5 1
4  7 1
5  9 0
5 12 0
5 11 0
5  3 1
5  1 1
5  4 1
end
Any help to calculate this would be most welcome and appreciated. Thank you.


Kenneth Zeng