Melogit and Weights [message #19633] |
Thu, 23 July 2020 09:38 ![Go to next message Go to next message](/theme/default/images/down.png) |
Yawo
Messages: 45 Registered: February 2019
|
Member |
|
|
Hello,
I am trying to fit a multilevel model examining HIV risk behaviors among those living with HIV using a pooled data from 23 countries.
My model nests individuals (level 1) into clusters (level 2). For melogit, I am aware I need to set weights at the two levels of my analysis, yet DHS only provides one weight.
From my review of forum here ( https://userforum.dhsprogram.com/index.php?t=msg&goto=13 522&&srch=multilevel+weights#msg_13522), I understand I can svyset my data, using the following:
gen weight=hiv05/1000000
gen weight2=1
svyset idhspsu, weight(weight) strata(idhsstrata) singleunit(centered) || _n, weight(weight2)
When I run my basic melogit, <svy: melogit condomless_spouse sex || idhspsu: >
I get the following error: "weights in variable weight not constant within groups defined by: idhspsu an error occurred when svy executed melogit"
I am sure I may not be doing something wrong here. I would be very grateful if any of you could point me in te right direction.
Thanks in advance of your assistance.
cY
[Updated on: Thu, 23 July 2020 09:39] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Re: Melogit and Weights [message #21792 is a reply to message #19759] |
Mon, 21 December 2020 21:12 ![Go to previous message Go to previous message](/theme/default/images/up.png) ![Go to next message Go to next message](/theme/default/images/down.png) |
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
|
|
|
|
|
Re: Melogit and Weights [message #21804 is a reply to message #21803] |
Tue, 22 December 2020 11:32 ![Go to previous message Go to previous message](/theme/default/images/up.png) ![Go to next message Go to next message](/theme/default/images/down.png) |
BillC
Messages: 6 Registered: July 2020
|
Member |
|
|
Thanks Tom (and Yawo) for your quick replies. (It seems I am not the only one slaving away during the holidays.... :-))
Your suggestion worked Tom- many thanks for it. I tried weighting by both the arithmetic and geometric mean and the estimates in my test regression were very close (but that's probably due to the fact I have a large sample).
Am curious to know more about the issues you have noticed with the MR27 dataset. Can you shed some more light on that - and on the enigmatic statement at the end to stay tuned? Does that mean you will revise the code in DHS Report 27?
Once again, thanks for the reply. Merry Christmas and Happy New year to all - may 2021 be an Annus Mirabilis for all.
|
|
|
|
Re: Melogit and Weights [message #21977 is a reply to message #21814] |
Tue, 12 January 2021 18:26 ![Go to previous message Go to previous message](/theme/default/images/up.png) ![Go to next message Go to next message](/theme/default/images/down.png) |
BillC
Messages: 6 Registered: July 2020
|
Member |
|
|
Hi Tom,
Another quick clarification on weight for multilevel analyses. To recap, I am combining the mens and womens datsets for a multilevel analyses. (Code is from DHS Report #27 (Multilevel Modeling Using DHS Surveys: A Framework to Approximate Level-Weights)
Two questions:
Q1: Do I need to adjust v005 BEFORE I run this code below?
gen wt=v005/1000000
gen DHSwt = v005/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)
........
Q2:if yes, then the adjustment factor for women = (population of 15-49yr women in country)/number of 15-49 yr women sampled; and for men = (population of men 15-49 yrs in country)/number of men 15-49 yrs sampled - as per the code below?
*adjusting weights of men and women in combined dataset
gen wtfactor=.
replace wtfactor=(xxxxxxxx/29461) if sex==2 //dividing population of women 15-49 yrs in country by number interviewed in 15-49 yrs
replace wtfactor=(yyyyyyy/10760) if sex==1//dividing population of men 15-49 yrs in country by number of men interviewed
label variable wtfactor "Multiplication factor for wt(v005)"
gen wt=v005/1000000
gen newwt=wt*wtfactor
label variable newwt "Population adjusted sample weight"
gen DHSwt = newwt/1000000
(then run code above...)
Many thanks!
Bill
|
|
|
|
|
|
Re: Melogit and Weights [message #26237 is a reply to message #26222] |
Tue, 21 February 2023 08:25 ![Go to previous message Go to previous message](/theme/default/images/up.png) |
Bridgette-DHS
Messages: 3151 Registered: February 2013
|
Senior Member |
|
|
Following is a response from Senior DHS staff member, Tom Pullum:
Yes, if you want to run a multilevel model that includes DV variables, you should use d005 as the weight and go through the same procedure to separate the individual-level and cluster-level weights as you would with the other weights.
|
|
|