// Generating indicators for husband, wife, son, and daughter
gen is_wife = (sex == 3 & (relationtohead == 1 | relationtohead == 2))
gen is_husband = (sex == 1 & (relationtohead == 1 | relationtohead == 2))
gen is_daughter = (sex == 3 & (relationtohead == 3 | relationtohead == 4))
gen is_son = (sex == 1 & (relationtohead == 3 | relationtohead == 4))
// Checking the number of husbands and wives in each household and wave
bysort household_id wave: egen wives_per_wave = total(is_wife)
bysort household_id wave: egen husbands_per_wave = total(is_husband)
// Determining if there is at most one husband and one wife in each household
bys household_id: egen max_husbands = max(husbands_per_wave)
bys household_id: egen max_wives = max(wives_per_wave)
bys household_id: gen unique_husband = (max_husbands == 1)
bys household_id: gen unique_wife = (max_wives == 1)
// Keeping households with at most one husband and one wife
bys household_id: keep if unique_husband == 1 & unique_wife == 1
However, although when browsing the data it appears that there is only when husband and one wife (across various waves) for each household, when I do:
distinct pidlink if is_wife == 1 and distinct pidlink if is_husband == 1, I still get more wives than husbands (regardless of waves given the distinct command. Thus, implying, that I have kept households where more than one wife exists).
I provide a data example below:
clear
input str10(household_id person_id) float(wave is_husband is_wife)
"0010651" "001060004" 5 0 1
"0010651" "001065102" 5 1 0
"0010651" "001065103" 5 0 0
"0010651" "001065104" 5 0 0
"0010851" "001080003" 5 1 0
"0010851" "001080012" 5 0 1
"0010851" "001085103" 5 0 0
"0010851" "001085104" 5 0 0
"0010851" "001085105" 5 0 0
"0010851" "001085106" 5 0 0
"0010851" "001085107" 5 0 0
"0012200" "001220001" 1 1 0
"0012200" "001220001" 2 1 0
"0012200" "001220001" 3 1 0
"0012200" "001220001" 4 1 0
"0012200" "001220001" 5 1 0
"0012200" "001220002" 1 0 1
"0012200" "001220002" 2 0 1
"0012200" "001220002" 3 0 1
"0012200" "001220002" 4 0 1
"0012200" "001220002" 5 0 1
"0012200" "001220003" 1 0 0
"0012200" "001220003" 2 0 0
"0012200" "001220003" 3 0 0
"0012241" "001220003" 4 1 0
"0012241" "001220003" 5 1 0
"0012200" "001220004" 1 0 0
"0012200" "001220004" 2 0 0
"0012200" "001220004" 3 0 0
"0012200" "001220004" 4 0 0
"0012200" "001220004" 5 0 0
"0012200" "001220005" 1 0 0
"0012200" "001220005" 2 0 0
"0012200" "001220005" 3 0 0
"0012200" "001220005" 4 0 0
"0012200" "001220005" 5 0 0
"0012200" "001220006" 1 0 0
"0012200" "001220006" 2 0 0
"0012200" "001220006" 3 0 0
"0012200" "001220006" 4 0 0
"0012200" "001220006" 5 0 0
"0012200" "001220007" 1 0 0
"0012200" "001220007" 2 0 0
"0012200" "001220007" 3 0 0
"0012200" "001220007" 4 0 0
"0012200" "001220007" 5 0 0
"0012200" "001220008" 1 0 0
"0012200" "001220008" 2 0 0
"0012200" "001220008" 3 0 0
"0012200" "001220009" 1 0 0
"0012200" "001220009" 2 0 0
"0012200" "001220009" 3 0 0
"0012200" "001220009" 4 0 0
"0012200" "001220010" 1 0 0
"0012200" "001220010" 2 0 0
"0012200" "001220010" 3 0 0
"0012200" "001220010" 4 0 0
"0012200" "001220010" 5 0 0
"0012241" "001220011" 4 0 1
"0012241" "001220011" 5 0 1
"0012241" "001220013" 4 0 0
"0012241" "001220013" 5 0 0
"0012200" "001220014" 4 0 0
"0012200" "001220014" 5 0 0
"0012200" "001220015" 4 0 0
"0012200" "001220015" 5 0 0
"0012241" "001224104" 4 0 0
"0012241" "001224104" 5 0 0
"0012241" "001224105" 4 0 0
"0012241" "001224105" 5 0 0
"0012241" "001224106" 5 0 0
"0012400" "001240001" 1 1 0
"0012400" "001240001" 2 1 0
"0012400" "001240001" 5 1 0
"0012400" "001240002" 1 0 1
"0012400" "001240002" 2 0 1
"0012400" "001240002" 5 0 1
"0012400" "001240003" 1 0 0
"0012400" "001240003" 2 0 0
"0012400" "001240003" 5 0 0
"0012400" "001240004" 1 0 0
"0012400" "001240004" 2 0 0
"0012400" "001240004" 5 0 0
"0012400" "001240005" 1 0 0
"0012400" "001240005" 2 0 0
"0012451" "001240005" 5 0 1
"0012400" "001240006" 1 0 0
"0012400" "001240006" 2 0 0
"0012400" "001240006" 5 0 0
"0012400" "001240007" 1 0 0
"0012400" "001240007" 2 0 0
"0012400" "001240007" 5 0 0
"0012400" "001240008" 1 0 0
"0012400" "001240008" 2 0 0
"0012400" "001240008" 5 0 0
"0012400" "001240009" 1 0 0
"0012400" "001240009" 2 0 0
"0012452" "001240009" 5 0 1
"0012400" "001240010" 1 0 0
"0012400" "001240010" 2 0 0
Thank you in advance,
Enrique
gen is_wife = (sex == 3 & (relationtohead == 1 | relationtohead == 2))
gen is_husband = (sex == 1 & (relationtohead == 1 | relationtohead == 2))
gen is_daughter = (sex == 3 & (relationtohead == 3 | relationtohead == 4))
gen is_son = (sex == 1 & (relationtohead == 3 | relationtohead == 4))
// Checking the number of husbands and wives in each household and wave
bysort household_id wave: egen wives_per_wave = total(is_wife)
bysort household_id wave: egen husbands_per_wave = total(is_husband)
// Determining if there is at most one husband and one wife in each household
bys household_id: egen max_husbands = max(husbands_per_wave)
bys household_id: egen max_wives = max(wives_per_wave)
bys household_id: gen unique_husband = (max_husbands == 1)
bys household_id: gen unique_wife = (max_wives == 1)
// Keeping households with at most one husband and one wife
bys household_id: keep if unique_husband == 1 & unique_wife == 1
However, although when browsing the data it appears that there is only when husband and one wife (across various waves) for each household, when I do:
distinct pidlink if is_wife == 1 and distinct pidlink if is_husband == 1, I still get more wives than husbands (regardless of waves given the distinct command. Thus, implying, that I have kept households where more than one wife exists).
I provide a data example below:
clear
input str10(household_id person_id) float(wave is_husband is_wife)
"0010651" "001060004" 5 0 1
"0010651" "001065102" 5 1 0
"0010651" "001065103" 5 0 0
"0010651" "001065104" 5 0 0
"0010851" "001080003" 5 1 0
"0010851" "001080012" 5 0 1
"0010851" "001085103" 5 0 0
"0010851" "001085104" 5 0 0
"0010851" "001085105" 5 0 0
"0010851" "001085106" 5 0 0
"0010851" "001085107" 5 0 0
"0012200" "001220001" 1 1 0
"0012200" "001220001" 2 1 0
"0012200" "001220001" 3 1 0
"0012200" "001220001" 4 1 0
"0012200" "001220001" 5 1 0
"0012200" "001220002" 1 0 1
"0012200" "001220002" 2 0 1
"0012200" "001220002" 3 0 1
"0012200" "001220002" 4 0 1
"0012200" "001220002" 5 0 1
"0012200" "001220003" 1 0 0
"0012200" "001220003" 2 0 0
"0012200" "001220003" 3 0 0
"0012241" "001220003" 4 1 0
"0012241" "001220003" 5 1 0
"0012200" "001220004" 1 0 0
"0012200" "001220004" 2 0 0
"0012200" "001220004" 3 0 0
"0012200" "001220004" 4 0 0
"0012200" "001220004" 5 0 0
"0012200" "001220005" 1 0 0
"0012200" "001220005" 2 0 0
"0012200" "001220005" 3 0 0
"0012200" "001220005" 4 0 0
"0012200" "001220005" 5 0 0
"0012200" "001220006" 1 0 0
"0012200" "001220006" 2 0 0
"0012200" "001220006" 3 0 0
"0012200" "001220006" 4 0 0
"0012200" "001220006" 5 0 0
"0012200" "001220007" 1 0 0
"0012200" "001220007" 2 0 0
"0012200" "001220007" 3 0 0
"0012200" "001220007" 4 0 0
"0012200" "001220007" 5 0 0
"0012200" "001220008" 1 0 0
"0012200" "001220008" 2 0 0
"0012200" "001220008" 3 0 0
"0012200" "001220009" 1 0 0
"0012200" "001220009" 2 0 0
"0012200" "001220009" 3 0 0
"0012200" "001220009" 4 0 0
"0012200" "001220010" 1 0 0
"0012200" "001220010" 2 0 0
"0012200" "001220010" 3 0 0
"0012200" "001220010" 4 0 0
"0012200" "001220010" 5 0 0
"0012241" "001220011" 4 0 1
"0012241" "001220011" 5 0 1
"0012241" "001220013" 4 0 0
"0012241" "001220013" 5 0 0
"0012200" "001220014" 4 0 0
"0012200" "001220014" 5 0 0
"0012200" "001220015" 4 0 0
"0012200" "001220015" 5 0 0
"0012241" "001224104" 4 0 0
"0012241" "001224104" 5 0 0
"0012241" "001224105" 4 0 0
"0012241" "001224105" 5 0 0
"0012241" "001224106" 5 0 0
"0012400" "001240001" 1 1 0
"0012400" "001240001" 2 1 0
"0012400" "001240001" 5 1 0
"0012400" "001240002" 1 0 1
"0012400" "001240002" 2 0 1
"0012400" "001240002" 5 0 1
"0012400" "001240003" 1 0 0
"0012400" "001240003" 2 0 0
"0012400" "001240003" 5 0 0
"0012400" "001240004" 1 0 0
"0012400" "001240004" 2 0 0
"0012400" "001240004" 5 0 0
"0012400" "001240005" 1 0 0
"0012400" "001240005" 2 0 0
"0012451" "001240005" 5 0 1
"0012400" "001240006" 1 0 0
"0012400" "001240006" 2 0 0
"0012400" "001240006" 5 0 0
"0012400" "001240007" 1 0 0
"0012400" "001240007" 2 0 0
"0012400" "001240007" 5 0 0
"0012400" "001240008" 1 0 0
"0012400" "001240008" 2 0 0
"0012400" "001240008" 5 0 0
"0012400" "001240009" 1 0 0
"0012400" "001240009" 2 0 0
"0012452" "001240009" 5 0 1
"0012400" "001240010" 1 0 0
"0012400" "001240010" 2 0 0
Thank you in advance,
Enrique
Comment