Project

General

Profile

Support #1171 ยป example7_ForeMoreThanOneWave.txt

Alita Nandi, 03/27/2019 02:24 PM

 

** 7.2 DATA PREPARATION: METHOD II
**********************************

foreach w in a b c d e f g h {

use "$dir/`w'_indresp", clear
keep `w'_hidp `w'_pno `w'_ppno `w'_ivfio `w'_sex `w'_dvage `w'_jbstat `w'_mastat_dv

// Create within-household unique partnership identifier.
gen `w'_partnum=cond(`w'_pno < `w'_ppno, `w'_pno, `w'_ppno) if `w'_ppno>0
lab var `w'_partnum "Partnership identifier, within household"

// Drop cases who are single or partner/spouse is not present in HH.
drop if `w'_ppno<=0

// Count the number of respondents for each partnership ID
// Those with non-responding spouses will have `w'_numinpart=1.
bysort `w'_hidp `w'_partnum: egen `w'_numinpart = sum(`w'_ppno > 0)
label variable `w'_numinpart "# respondents from partnership (max 2)"
tab `w'_numinpart

sort `w'_hidp `w'_partnum `w'_pno
list `w'_hidp `w'_partnum `w'_pno `w'_ppno `w'_numinpart in 1/50, sepby(`w'_hidp)

// Keep only matched cases, that is, where both partners are present in the HH
// and both are respondents.
keep if `w'_numinpart==2

// Assign spouse variable values
bysort `w'_hidp `w'_partnum: ge sp_`w'_dvage=cond(_n==2,`w'_dvage[1],`w'_dvage[2],.) ///
if `w'_partnum<.
lab val sp_`w'_dvage `w'_dvage

foreach v in `w'_sex `w'_mastat_dv `w'_jbstat {
bysort `w'_hidp `w'_partnum: ge sp_`v' = cond(_n==2, `v'[1], `v'[2], .) ///
if `w'_partnum < .
lab val sp_`v' `v'
}

rename `w'_* *
g wave=strpos("abcdefgh","`w'")
save `w'_couples, replace
}

    (1-1/1)