Home » Data » Weighting data » Melogit and Weights (Weighting Issues for multilevel models)
Re: Melogit and Weights [message #21792 is a reply to message #19759] |
Mon, 21 December 2020 21:12 |
BillC
Messages: 6 Registered: July 2020
|
Member |
|
|
Hi all,
I am trying to replicate the code in "Multilevel Modeling Using DHS Surveys...:Methodological Report 27" on a combined men and women data set from Afghanistan and also trying to adjust the weights of men and women in this combined dataset.
But am running into the dreaded "weights in variable wt2 not constant within groups defined by: v001" error when attempting to run melogit. When I run the diagnostic code at the end to see how many cases have different weights, I get dif==15,433.
Any suggestions on how to do this correctly?
Thanks!
Here is my code (apologies for its length):
do "C:\Users\Afghanistan\Appending men and women datasets.do"
*This is adapted from the Zimbabwe code at the end of the DHS Report #27
* a_c_h completed clusters by strata
gen a_c_h=.
levelsof v022, local(lstrata)
foreach ls of local lstrata {
tab v021 if v022==`ls', matrow(T)
scalar stemp=rowsof(T)
replace a_c_h=stemp if v022==`ls'
}
* A_h total number of census clusters by strata; from Table A2 of Afghanistan Final Report; pg 311.
gen A_h = 0
*Urban # EAs
replace A_h = 1870 if v022 == 1
..etc...
replace A_h = 119 if v022 == 68
* M_h average number of households per cluster by strata - from Table A2 of Afghanistan Final Report; pg 311.
gen M_h = 0
*urban - avg # households per EA
replace M_h = 239.8 if v022 == 1
...etc.....
replace M_h = 181.5 if v022 == 68
* m_c total number of completed households - Section 1.9, pg 5 of Afghan Final Report
gen m_c= 24395
* M total number of households in country - Table A1, pg 310 in Afghan Final Report
gen M = 4269415
* S_h households selected per stratum - Section A3, pg 312 of Afghan Final Report
gen S_h = 27
*adjusting weights of men and women in combined dataset
gen wtfactor=0
replace wtfactor=(16727000/29461) if sex==2 //dividing population of women by number interviewed in 15-49 yrs
replace wtfactor=(17686000/10760) if sex==1 //dividing population of men by number of men interviewed
gen wt=v005/1000000
gen newwt=wt*wtfactor
label variable newwt "Population adjusted sample weight"
gen DHSwt = newwt/1000000
* 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)
*Step 2. Approximate the Level-2 weight
* f the variation factor
gen f = d_HH / ((A_h/a_c_h) * (M_h/S_h))
scalar alpha=0.5
gen wt2 = (A_h/a_c_h)*(f^alpha)
gen wt1 = d_HH/wt2
* Svyset
svyset v001, strata(v022) weight(wt2) singleunit(centered) || _n, weight(wt1)
svy: melogit v474 i.sex ||v001:, or
**for testing
bysort v001: gen dif = 0
replace dif = 1 if v001 == v001[_n-1] & wt2 != wt2[_n-1]
browse if dif == 1
count if dif==1
|
|
|
|
|
Melogit and Weights
By: Yawo on Thu, 23 July 2020 09:38
|
|
|
Re: Melogit and Weights
|
|
|
Re: Melogit and Weights
By: Yawo on Thu, 06 August 2020 00:47
|
|
|
Re: Melogit and Weights
|
|
|
Re: Melogit and Weights
By: Yawo on Thu, 06 August 2020 12:15
|
|
|
Re: Melogit and Weights
|
|
|
Re: Melogit and Weights
By: Yawo on Fri, 07 August 2020 10:04
|
|
|
Re: Melogit and Weights
By: Yawo on Mon, 10 August 2020 11:01
|
|
|
Re: Melogit and Weights
By: BillC on Mon, 21 December 2020 21:12
|
|
|
Re: Melogit and Weights
By: Yawo on Tue, 22 December 2020 04:32
|
|
|
Re: Melogit and Weights
|
|
|
Re: Melogit and Weights
By: BillC on Tue, 22 December 2020 11:32
|
|
|
Re: Melogit and Weights
|
|
|
Re: Melogit and Weights
By: BillC on Tue, 12 January 2021 18:26
|
|
|
Re: Melogit and Weights
|
|
|
Re: Melogit and Weights
By: BillC on Wed, 13 January 2021 09:57
|
|
|
Re: Melogit and Weights
|
|
|
Re: Melogit and Weights
|
Goto Forum:
Current Time: Sat Nov 23 09:43:49 Coordinated Universal Time 2024
|