The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Topics » General » Multilevel modeling (Problems with svy:melogit command while using weights)
Re: Multilevel modeling [message #24818 is a reply to message #24792] Fri, 15 July 2022 14:47 Go to previous messageGo to previous message
Janet-DHS is currently offline  Janet-DHS
Messages: 507
Registered: April 2022
Senior Member
Following is a response from DHS Senior Sampling Specialist, Mahmoud Elkasabi:

Yourcode has some mistakes, such as using the wrong values for v022 (I believe this is the reason for the errors) and the wrong number of completed HHs.
Below a fixed copy of the code that works in my side.

* a_c_h completed clusters by strata
gen a_c_h=.
quietly levelsof v022, local(lstrata)
quietly foreach ls of local lstrata {
tab v021 if v022==`ls', matrow(T)
scalar stemp=rowsof(T)
replace a_c_h=stemp if v022==`ls'
}


* check v022 values/labels
codebook v022 , tabulate(99)

* A_h total number of census clusters by strata
gen A_h = 0
replace A_h = 433 if v022 == 10
replace A_h = 41 if v022 == 20
replace A_h = 53 if v022 == 21
replace A_h = 32 if v022 == 22
replace A_h = 31 if v022 == 23
replace A_h = 50 if v022 == 24
replace A_h = 28 if v022 == 25
replace A_h = 25 if v022 == 26
replace A_h = 25 if v022 == 27
replace A_h = 15 if v022 == 28
replace A_h = 22 if v022 == 29
replace A_h = 6 if v022 == 30
replace A_h = 14 if v022 == 31
replace A_h = 11 if v022 == 32
replace A_h = 13 if v022 == 33
replace A_h = 29 if v022 == 34
replace A_h = 33 if v022 == 35
replace A_h = 23 if v022 == 36
replace A_h = 32 if v022 == 37
replace A_h = 27 if v022 == 38
replace A_h = 54 if v022 == 39

* M_h average number of households per cluster by strata
gen M_h = 0
replace M_h = 51 if v022 == 10
replace M_h = 62 if v022 == 20
replace M_h = 64 if v022 == 21
replace M_h = 74 if v022 == 22
replace M_h = 65 if v022 == 23
replace M_h = 58 if v022 == 24
replace M_h = 61 if v022 == 25
replace M_h = 62 if v022 == 26
replace M_h = 69 if v022 == 27
replace M_h = 65 if v022 == 28
replace M_h = 58 if v022 == 29
replace M_h = 50 if v022 == 30
replace M_h = 63 if v022 == 31
replace M_h = 59 if v022 == 32
replace M_h = 68 if v022 == 33
replace M_h = 60 if v022 == 34
replace M_h = 70 if v022 == 35
replace M_h = 69 if v022 == 36
replace M_h = 74 if v022 == 37
replace M_h = 56 if v022 == 38
replace M_h = 68 if v022 == 39

* m_c total number of completed households (added from the HR dataset)
gen m_c= 6050

* M total number of households in country
gen M = 58277

* S_h households selected per stratum
gen S_h = 25

gen DHSwt = v005 / 1000000

************************************************************ ************
* Stage B *** Approximate Levels-weight ***
************************************************************ ************

* Steps to approximate Level-1 and Level-2 weights from Household or Individual Weights
*Step 1. De-normalize the final weight, using approximated normalization factor
gen d_HH = DHSwt * (M/m_c)
gen dv_HH = (d005/1000000) * (M/m_c)

*Step 2. Approximate the Level-2 weight
* f the variation factor
gen f = d_HH / ((A_h/a_c_h) * (M_h/S_h))

* Calculating the levels-weight based on different values of alpha
local alphas 0 0.1 .25 .50 .75 0.90 1
local i = 1

foreach dom of local alphas{
gen wt2_`i' = (A_h/a_c_h)*(f^`dom')
gen wt1_`i' = d_HH/wt2_`i'
gen d1_`i' = dv_HH/wt2_`i'
local ++i
}
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Trend analysis with different number of 'PSU' and 'Strata'
Next Topic: Variable v034: merging datasets
Goto Forum:
  


Current Time: Wed Oct 4 23:11:38 Coordinated Universal Time 2023