Dear sir

I am working with Census data. To make it simple, consider a database as follows:
id family_id position (in family) religion
1 1 head (1) A
2 1 partner (2) A
3 1 son (3) A
4 2 head (1) A
5 2 partner (2) B
6 3 head (1) A
7 4 head (1) B
8 4 partner (2) A
9 4 son (3) A
I need to count the number of same-religion and different-religion marriages.

In this very simple database above, the result should be: AA = 1; AB = 1; BA = 1.

So far I managed to create a new variable "position-religion" (1-A; 2-A; 3-A; 1A; 2-B; ...).

I guess I have to create another new variable, assigning the position_religion of the head of the family to all the other ids in the same family_ids. If I manage to do that, a simple frequency table will provide the result.

Could you please help me in creating this new variable?

Thanks in advance
Sergio Goldbaum