Dear Stata users, I have the following data sample where fam_id represents the family, hh_count represents the number of family members within a family. Mother, father, and person_id are the string variables that identify the person and other family members. In the last column, I find the location of the mother of the corresponding family member.


clear
input byte fam_id str1(mother father person_id) byte(hh_count place_mother)
1 "" "" "x" 1 .
1 "x" "y" "d" 2 1
1 "x" "y" "e" 3 1
1 "x" "y" "f" 4 1
1 "z" "b" "y" 5 6
1 "a" "c" "z" 6 .
end

For example, the person e's mother is x and located at the 1st column of person_id.

I want to create a new variable that identifies the mother. What I require is something like this:

input byte fam_id str1(mother father person_id) byte(hh_count place_mother) float mother_find
1 "" "" "x" 1 . 1
1 "x" "y" "d" 2 1 .
1 "x" "y" "e" 3 1 .
1 "x" "y" "f" 4 1 .
1 "z" "b" "y" 5 6 .
1 "a" "c" "z" 6 . 2
end

Could you please help me with that?

Regards,