I have this data:
The columns are year, country, pid(personal ID), hhid(household ID) and rb240(partner ID). I'm interested in creating an indicator that identifies partners within a household. For example, in row 1 you can see that in household 2658500 (column hhid), person 265850002 (pid column) is in a relationship with 265850001 (column rb240). Equivalently, in row 2 person 265850001(pid column) is in a relationship with person 265850002 (rb240). Within that household, then, the couple should have a 1 for both. In row 21 there's a household that has two couples in the same residence. The indicator should have a 1 for one of the couples and 2 for the other couple.
The final results should be like this (with the code being able to identify N couples within a household and not just only one or two.)
Any help is appreciated!
Code:
clear input int year str2 country str10 pid str8 hhid str10 rb240 2010 "AT" "265850002" "2658500" "265850001" 2010 "AT" "265850001" "2658500" "265850002" 2010 "AT" "265870001" "2658700" "." 2010 "AT" "265900003" "2659000" "." 2010 "AT" "265900004" "2659000" "." 2010 "AT" "265900002" "2659000" "265900001" 2010 "AT" "265900001" "2659000" "265900002" 2010 "AT" "265910002" "2659100" "265910001" 2010 "AT" "265910001" "2659100" "265910002" 2010 "AT" "265940003" "2659400" "." 2010 "AT" "265940005" "2659400" "." 2010 "AT" "265940004" "2659400" "." 2010 "AT" "265940002" "2659400" "265940001" 2010 "AT" "265940001" "2659400" "265940002" 2010 "AT" "265950001" "2659500" "." 2010 "AT" "265970002" "2659700" "265970001" 2010 "AT" "265970001" "2659700" "265970002" 2010 "AT" "265980002" "2659800" "265980001" 2010 "AT" "265980001" "2659800" "265980002" 2010 "AT" "266050003" "2660500" "." 2012 "IT" "265340001" "2653400" "265340002" 2012 "IT" "265340002" "2653400" "265340001" 2012 "IT" "265340003" "2653400" "265340004" 2012 "IT" "265980004" "2653400" "265340003" 2012 "IT" "266050005" "2653400" "." end
The final results should be like this (with the code being able to identify N couples within a household and not just only one or two.)
Code:
clear input int year str2 country str10 pid str8 hhid str10 rb240 str2 n 2010 "AT" "265850002" "2658500" "265850001" "1" 2010 "AT" "265850001" "2658500" "265850002" "1" 2010 "AT" "265870001" "2658700" "." "." 2010 "AT" "265900003" "2659000" "." "." 2010 "AT" "265900004" "2659000" "." "." 2010 "AT" "265900002" "2659000" "265900001" "1" 2010 "AT" "265900001" "2659000" "265900002" "1" 2010 "AT" "265910002" "2659100" "265910001" "1" 2010 "AT" "265910001" "2659100" "265910002" "1" 2010 "AT" "265940003" "2659400" "." "." 2010 "AT" "265940005" "2659400" "." "." 2010 "AT" "265940004" "2659400" "." "." 2010 "AT" "265940002" "2659400" "265940001" "1" 2010 "AT" "265940001" "2659400" "265940002" "1" 2010 "AT" "265950001" "2659500" "." "." 2010 "AT" "265970002" "2659700" "265970001" "1" 2010 "AT" "265970001" "2659700" "265970002" "1" 2010 "AT" "265980002" "2659800" "265980001" "1" 2010 "AT" "265980001" "2659800" "265980002" "1" 2010 "AT" "266050003" "2660500" "." "." 2012 "IT" "265340001" "2653400" "265340002" "1" 2012 "IT" "265340002" "2653400" "265340001" "1" 2012 "IT" "265340003" "2653400" "265340004" "2" 2012 "IT" "265980004" "2653400" "265340003" "2" 2012 "IT" "266050005" "2653400" "." "." end