Hi everyone,

I am working with a panel data set and want to create intergenerational linkages between parents and kids.

My data looks like this:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str9(hhid pidlink) byte(ar02 ar10 ar11)
"120100106" "001060001"  1 52 52
"120100106" "001060002"  2 52 52
"120100106" "001060003"  3  1  2
"120100106" "001060004"  3  1  2
"120100106" "001060005"  3  1  2
"120100106" "001060006"  3  1  2
"120100108" "001080001"  1 52 11
"120100108" "001080002"  2 51 51
"120100108" "001080003"  3  1  2
"120100108" "001080004"  3  1  2
"120100108" "001080005"  3  1  2
"120100108" "001080006"  3  1  2
"120100108" "001080007"  3  1  2
"120100108" "001080008"  3  1  2
"120100108" "001080009"  3  1  2
"120100108" "001080010"  3  1  2
"120100108" "001080011"  6 52 52
"120100122" "001220001"  1 52 51
"120100122" "001220002"  2 51 51
"120100122" "001220003"  3  1  2
"120100122" "001220004"  3  1  2
"120100122" "001220005"  3  1  2
"120100122" "001220006"  3  1  2
"120100122" "001220007"  3  1  2
"120100122" "001220008"  3  1  2
"120100122" "001220009"  3  1  2
"120100122" "001220010"  3  1  2
"120100124" "001240001"  1 52 52
"120100124" "001240002"  2 52 51
"120100124" "001240003"  3  1  2
"120100124" "001240004"  3  1  2
"120100124" "001240005"  3  1  2
"120100124" "001240006"  3  1  2
"120100124" "001240007"  3  1  2
"120100124" "001240008"  3  1  2
"120100124" "001240009"  3  1  2
"120100124" "001240010"  3  1  2
"120100124" "001240011"  5 51 51
"120100124" "001240012" 10  3 11
"120100124" "001240013" 10  3 11
"120100125" "001250001"  1 52 52
"120100125" "001250002"  2 52 52
"120100125" "001250003"  3  1  2
"120100125" "001250004"  3  1  2
"120100125" "001250005"  3  1  2
"120100125" "001250006"  3  1  2
"120100125" "001250007"  3  1  2
"120100129" "001290001"  1 52 51
"120100129" "001290002"  2 51 51
"120100129" "001290003"  3  1  2
"120100129" "001290004"  3  1  2
"120100129" "001290005"  3  1  2
"120100129" "001290006"  3  1  2
"120100201" "002010001"  1 52 52
"120100201" "002010002"  2 51 52
"120100201" "002010003"  3  1  2
"120100201" "002010004"  5 52 52
"120100201" "002010005" 10 51 51
"120100201" "002010006" 10 51 51
"120100202" "002020001"  1 52  3
"120100202" "002020002"  2 51 51
"120100202" "002020003"  6 52 52
"120100202" "002020004"  8 52  3
"120100202" "002020005"  8 52  3
"120100202" "002020006"  8 52  3
"120100202" "002020007"  8 52  3
"120100203" "002030001"  1 52 52
"120100203" "002030002"  2 52 52
"120100203" "002030003"  3  1  2
"120100204" "002040001"  1 51 51
"120100204" "002040002"  2 52 51
"120100204" "002040003"  3  1  2
"120100204" "002040004"  3  1  2
"120100204" "002040005"  3  1  2
"120100205" "002050001"  1 51 51
"120100205" "002050002"  2 52 52
"120100205" "002050003"  3  1  2
"120100205" "002050004"  3  1  2
"120100205" "002050005"  3  1  2
"120100206" "002060001"  1 52 52
"120100206" "002060002" 10 51 52
"120100206" "002060003" 10 51 52
"120100206" "002060004" 10 51 52
"120100206" "002060005" 10 51 52
"120100209" "002090001"  1 52 52
"120100209" "002090002"  2 52  5
"120100209" "002090003"  3  1  2
"120100209" "002090004"  3  1  2
"120100209" "002090005"  6 52 52
"120100209" "002090006"  9 52  5
"120100209" "002090007"  9 52  5
"120100210" "002100001"  1 51 51
"120100210" "002100002"  2 51 52
"120100210" "002100003"  3  1  2
"120100211" "002110001"  1 52 52
"120100211" "002110002"  2 51 51
"120100211" "002110003"  3  1  2
"120100211" "002110004"  3  1  2
"120100211" "002110005"  3  1  2
"120100212" "002120001"  1 52 52
end
hhid is the household id
pidlink is a unique person identifier
ar02 is the relationship to the head of the household (1=head of the household, 2=husband/wife, 3=child, etc.)
ar10 is the line number of the father
ar11 is the line number of the mother
ar10 and ar11 take on the value 52 if the parent is dead.

I want to have a new variable (mom_pidlink) that takes on the value of the mother's pidlink.
For example, it should look like this for the first household:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str9(hhid pidlink) byte(ar02 ar10 ar1) str9(mom_pidlink)
"120100106" "001060001"  1 52 52 
"120100106" "001060002"  2 52 52
"120100106" "001060003"  3  1  2 "001060002"
"120100106" "001060004"  3  1  2 "001060002"
"120100106" "001060005"  3  1  2 "001060002"
"120100106" "001060006"  3  1  2 "001060002"
end

In the end, I want to merge more variables over mom_pidlink and have all the information in one row.


Any help is appreciated!