I'm new to stata (15.1), and I am trying to count the number of interactions that firms have between each other. I am looking at alliances between two firms, that can either be a participant, participant parent or participant ultimate parent (p, pp, pup). My data looks as follows:
ID Year P1 P2 PP1 PP2 PUP1 PUP2
1 1995 a1 b1 c1 d1 e1 f1
2 1995 a2 b2 c2 d2 e2 f2
3 1996 a3 b3 c1 d1 e3 f3
4 1997 a1 b1 c3 d3 e4 f4

I am now trying to write a loop to count all the id's that include either one of the 6 names, and another that will count how many cases have the same two partners (p1, pp1, pup1 & p2, pp2, pup2).
For example, ID 1 and 3 both have the same PP1 and PP2, leaving a count of C1=2, D1=2 and 2 repeated interactions between the dyad C1&D1.

However, I am not sure how to proceed with the writing of this code without removing parts of the dataset in the process.

Thank you in advance for taking the time to look at this. Right now, any help is greatly appreciated!