|
// What does this syntax file do?
|
|
// It creates a dataset of individuals with information
|
|
// about their co-resident parents match to them
|
|
// The output files are named file_a, file_b,...
|
|
|
|
clear all
|
|
set more off
|
|
|
|
|
|
// Step 1: Replace "wheremydataisstored" with the filepath where
|
|
// you have saved the data folders ukhls_w1, ukhls_w2....
|
|
global data "wheremydataisstored"
|
|
|
|
local tm "mother"
|
|
local tf "father"
|
|
|
|
foreach w in a { // Step 2: choose the waves
|
|
local i=strpos("abcdefghijklmnopqrstuvwxyz","`w'")
|
|
|
|
// Step 3: Decide if you want only biological parents
|
|
// or all(biological, adopted, step) parents. If biological
|
|
// parents use `w'_`k'npid instead of `w'_`k'nspid which is
|
|
// for all parents
|
|
foreach k in m f {
|
|
use "$data/ukhls_w`i'/`w'_indall", clear
|
|
drop if `w'_`k'nspid<0
|
|
keep `w'_`k'nspid pidp
|
|
rename pidp kpidp
|
|
rename `w'_`k'nspid pidp
|
|
|
|
// Step 4: Define the list of parental variables you want to add
|
|
local vars `w'_age_dv `w'_employ
|
|
|
|
// Step 5: Choose the data file from where you want to
|
|
// add parental variables
|
|
local file indall
|
|
|
|
merge m:1 pidp using "$data/ukhls_w`i'/`w'_`file'", nogen keep(3) ///
|
|
keepus(`vars')
|
|
|
|
foreach var of local vars {
|
|
rename `var' `var'_`k'
|
|
local l`var': var label `var'
|
|
lab var `var' `"`t`k'': `l`var''"'
|
|
}
|
|
drop pidp
|
|
rename kpidp pidp
|
|
merge 1:1 pidp using "$data/ukhls_w`i'/`w'_`file'"
|
|
|
|
// check
|
|
assert _merge==2|_merge==3
|
|
|
|
// recode missing parental information to -8
|
|
foreach var of local vars {
|
|
replace `var'_`k'=-8 if _merge==2
|
|
}
|
|
|
|
// Step 6: keep the variables you have created
|
|
keep pidp `w'_age_dv *_`k'
|
|
|
|
// check
|
|
isid pidp
|
|
save `k', replace
|
|
}
|
|
use m, clear
|
|
merge 1:1 pidp using f
|
|
// check
|
|
assert _merge==3
|
|
drop _merge
|
|
|
|
order pidp, first
|
|
order *_m *_f, last
|
|
|
|
save file_`w', replace
|
|
su
|
|
d
|
|
}
|
|
|
|
// clean up temporary files
|
|
erase m.dta
|
|
erase f.dta
|
|
|
|
|