|
* Keeping the necessary vars in the child data for merging
|
|
|
|
// CHILD
|
|
|
|
foreach w in a b c d e f g h i j k l {
|
|
|
|
// Open the individual level file
|
|
|
|
use "${ukhls}/`w'_child", clear
|
|
|
|
// Keep only the variables that exist in the current dataset
|
|
|
|
keep pidp pid `w'_hidp `w'_pno `w'_childpno `w'_hgbiom `w'_hgbiof
|
|
|
|
// Save one file for each wave
|
|
|
|
save "${tempdata}/`w'_child", replace
|
|
}
|
|
|
|
* Then, I keep the necessary variables in the a_natchild data by dropping the duplicates before merging with the child to create a new data that includes birthweight measures for children
|
|
|
|
// NATCHILD
|
|
|
|
use "${ukhls}\a_natchild", clear
|
|
|
|
* In the natchild data, we have pidp, `w'_hidp, `w'_pno, `a'_childno
|
|
|
|
keep pidp a_hidp a_pno a_childno a_lchlv a_lchyd4 a_lchno a_bwtxp a_bwtel a_bwtwk a_bwt a_bwtlb a_bwtoz a_bwtk a_bwtg5 a_brfed a_brfedend a_brfedend2
|
|
|
|
*isid pidp // I know that isid pidp does not work as the data does not uniquely identify and stands for
|
|
|
|
* Hence I first tried to keep those with the birthweight information
|
|
|
|
drop if a_bwtlb < 0
|
|
|
|
drop if a_bwtoz < 0
|
|
|
|
* Then tried to keep those with the childpno
|
|
|
|
keep if a_lchno > 0
|
|
|
|
* Or tried to drop duplicates
|
|
|
|
duplicates report pidp
|
|
|
|
duplicates drop pidp, force
|
|
|
|
save "${tempdata}/a_natchild", replace
|
|
|
|
* I tried to merge it using the method suggested for the child-newborn match, SEE BELOW
|
|
|
|
use "${tempdata}/a_child", clear
|
|
|
|
sort a_hidp a_pno
|
|
|
|
merge 1:m a_hidp a_pno using "${tempdata}/a_natchild"
|
|
|
|
// NEWBORN
|
|
|
|
foreach w in b c d e f g h i j k l {
|
|
|
|
// Open the individual level file
|
|
|
|
use "${ukhls}/`w'_newborn", clear
|
|
|
|
// Keep only the variables that exist in the current dataset
|
|
|
|
keep pidp `w'_hidp `w'_pno `w'_newchno `w'_lchlv `w'_lchyd4 `w'_lchsx `w'_lchby4 `w'_lchal `w'_lchno `w'_bwtxp `w'_bwtel `w'_bwtwk `w'_bwt `w'_bwtlb `w'_bwtoz `w'_bwtk `w'_bwtg5 `w'_brfed `w'_brfedend `w'_brfedend2
|
|
|
|
duplicates drop pidp, force
|
|
|
|
// Save one file for each wave
|
|
|
|
save "${tempdata}/`w'_newborn", replace
|
|
}
|
|
|
|
* Now, merging the child data with newborn in a loop
|
|
|
|
foreach w in b c d e f g h i j k l {
|
|
|
|
use "${ukhls}/`w'_child", clear
|
|
|
|
sort `w'_hidp `w'_pno
|
|
merge 1:m `w'_hidp `w'_pno using "${tempdata}/`w'_newborn"
|
|
rename _merge mergechildnewborn
|
|
|
|
// Save one file for each wave
|
|
|
|
save "${tempdata}/`w'_child", replace
|
|
}
|
|
|
|
log close
|