The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Dataset use in Stata » family structure
Re: family structure [message #18132 is a reply to message #18062] Wed, 25 September 2019 05:41 Go to previous messageGo to previous message
Mr_Bokoboko is currently offline  Mr_Bokoboko
Messages: 2
Registered: September 2019
Member
Morning,

Could this work?

* identify nuclear households: head, spouse, children
clear all
set mem 1000
cd "C:\Users\Bokoboko\Desktop\SADHS\DATASET\ZAPR71DT"
use "ZAPR71FL", clear

** ========================================================================== **

*keep hhid hv001 hv002 hvidx hv101-hv105 hv111-hv114 
label list HV101

** ========================================================================== **

cap drop relationship
gen relationship=99
replace relationship = 1 if hv101 == 1
replace relationship = 2 if hv101 == 2
replace relationship = 3 if inlist(hv101,3,11,13,14)
replace relationship = 4 if hv101 == 8
replace relationship = 5 if hv101 == 6
*replace relationship = 6 if hv101 == ??
replace relationship = 7 if hv101 == 5
replace relationship = 8 if inlist(hv101,4,7,10)
replace relationship = 9 if hv101 == 12
label define relationship 1	"Head/acting head" 2 "Husband/wife/partner" ///
3 "Son/daughter/stepchild/adopted child" 4 "Brother/sister/stepbrother/stepsister" ///
5 "Father/mother/stepfather/stepmother" 6 "Grandparent/great grandparent" ///
7 "Grandchild/great grandchild" 8 "Other relative" 9 "Non-related persons" ///
99 "Unspecified"
label var relationship "Relationship to head"
label val relationship relationship

sort hhid hv001 hv002 hvidx

by hhid: generate hhsize=_N
egen hhtag = tag(hhid)

sort hv001 hv002

save PHtemp.dta, replace

** ========================================================================== **

gen n=1
levelsof relationship, local(levels_hv101)
foreach li of local levels_hv101 {
gen n_`li'=0
replace n_`li'=1 if relationship==`li'
}
*
collapse (sum) n*, by(hhsize hv001 hv002)

tab1 n*, m


cap drop family_type
gen family_type=.
*replace family_type=1 if n_1==1 & n_2==1 & n_3>0 & n==n_1+n_2+n_3
replace family_type = 1 if hhsize == 1
replace family_type = 2 if (n_1 >=1 & n_2 >=1) | (n_1 >=1 & n_3 >=1)
replace family_type = 3 if (n_4 >=1 | n_5>=1) | (/*n_6 >=1 |*/ n_7>=1) | (n_8 >=1)
replace family_type = 4 if n_9 >= 1
replace family_type = . if n_1 == 0
label define family_type 1"Single" 2"Nuclear" 3"Extended" 4"Complex" 9"Unspecified"
label var family_type "Family type / household composition"
label val family_type family_type

tab family_type, m

** ========================================================================== **

** MERGE **
sort hv001 hv002

merge 1:m hv001 hv002 using "C:\Users\MlulekiT\Desktop\SADHS 2016 DATA\DATASETS\ZAPR71DT\PHtemp.dta"
duplicates report
cap drop _merge

order hhid hhsize hv001 hv002 hv005 family_type hv105 hv104 hv217 hv021 hv023 relationship ///
n n_1 n_2 n_3 n_4 n_5 n_7 n_8 n_9 *

** ========================================================================== **

** SURVEY SET
gen person_wgt=hv005/1000000
gen psu =    hv021
gen strata = hv023

svyset psu [pw = person_wgt], strata(strata) vce(linearized)

** ========================================================================== **

tab hv101 family_type, m
svy: tab family_type, percent format(%9.1f) col miss
tabstat hhsize [aw=person_wgt], by(family_type) stat(mean median sd min max) format(%9.1f)
tabstat hhsize if hhtag==1 [aw=person_wgt], by(family_type) stat(mean median sd min max) format(%9.1f)

***************

tab family_type [iw= person_wgt], m
svy: tab family_type, count format(%9.0f) miss
svy: tab family_type, percent format(%9.1f) col miss

svy: tab hv270 family_type, count format(%9.0f) miss
svy: tab hv270 family_type, percent format(%9.1f) row miss

svy: tab hv109 family_type, percent format(%9.1f) row miss

** ========================================================================== **

exit
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Panel data creation in women file of different round of DHS in India
Next Topic: Merging of couple and children dataset
Goto Forum:
  


Current Time: Sun Dec 22 04:23:58 Coordinated Universal Time 2024