The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » IPUMS Demographic and Health Surveys (IPUMS-DHS)  » Melogit and Weights
Melogit and Weights [message #19634] Thu, 23 July 2020 10:19 Go to next message
Yawo is currently offline  Yawo
Messages: 28
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
Re: Melogit and Weights [message #19635 is a reply to message #19634] Thu, 23 July 2020 10:50 Go to previous messageGo to next message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 710
Registered: January 2013
Senior Member
I suspect that the problem is that you do not have constant weights for each PSU. You can check this by summarizing the weight variable by the idhspsu - the minimum and the maximum should be identical in all cases. For example:
sort idhspsu
by idhspsu: summ weight
Be warned that the output is going to be very long, and you probably want to capture the output and process it to find if there are PSUs where the weight is not a constant.

An alternative way of doing the same is:
sort idhspsu
gen dif = 0
replace dif = 1 if idhspsu == idhspsu[_n-1] & weight != weight[_n-1]
browse if dif == 1
Any case where dif equals 1 indicates a PSU where the weight is not constant.
Re: Melogit and Weights [message #19636 is a reply to message #19635] Thu, 23 July 2020 17:09 Go to previous messageGo to next message
BillC
Messages: 2
Registered: July 2020
Member
Hi Trevor,

Am facing the same issue as Yawo. I am examining a multilevel model in Afghanistan and want to run a random intercept model with region (v024) as the second level.

A) Here is my code (based on Shireen's post):
gen wt=v005/1000000
gen wt2=1
svyset region, weight(wt) strata(v023) , singleunit(centered) || _n, weight(wt2)

Stata output follows:

Note: Stage 1 is sampled with replacement; further stages will be ignored for variance estimation.

pweight: <none>
VCE: linearized
Single unit: centered
Strata 1: v023
SU 1: region
FPC 1: <zero>
Weight 1: wt
Strata 2: <one>
SU 2: <observations>
FPC 2: <zero>
Weight 2: wt2

B) Here is the Stata output for the svy: melogit model

(running melogit on estimation sample)
weights in variable wt not constant within groups defined by: region
an error occurred when svy executed melogit

C) Here is the output of the code you suggested to check if there is variation in the min/max of wt2:

wt2 | Freq. Percent Cum.
------------+-----------------------------------
1 | 29,461 100.00 100.00
------------+-----------------------------------
Total | 29,461 100.00

Thoughts?

Thanks!
Re: Melogit and Weights [message #19637 is a reply to message #19636] Thu, 23 July 2020 17:19 Go to previous messageGo to next message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 710
Registered: January 2013
Senior Member
Wt2 is not the variable to look at. You know that is constant. You need to look at wt1.
Re: Melogit and Weights [message #19638 is a reply to message #19637] Thu, 23 July 2020 17:27 Go to previous messageGo to next message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 710
Registered: January 2013
Senior Member
For BillC, in fact in your case, I think you have a different issue. You are working with just one survey, so I think your problem is in the specification of the melogit command and the levelvars that you are using. It looks like you are using only region as your levelvars, but I think you need to include PSU. Your svyset command is using region instead of PSU (v021) as well - that needs to use PSU.
Re: Melogit and Weights [message #19639 is a reply to message #19638] Thu, 23 July 2020 17:46 Go to previous messageGo to next message
BillC
Messages: 2
Registered: July 2020
Member
Hi Trevor,

Many thanks for the quick reply - appreciate it. Its been a long day tussling with code, so my brain is a bit addled.

I used this code for svyset and it worked well for the logit command:
generate wgt = v005/1000000
svyset[pw=wgt], psu(v021) strata(v022)
svy: logit outcome iv1 iv2, or (this worked fine)

If I want to use v024(region) as the clustering variable for Level 2, what is the svyset code?

Thanks again,


Re: Melogit and Weights [message #19640 is a reply to message #19639] Thu, 23 July 2020 18:46 Go to previous messageGo to next message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 710
Registered: January 2013
Senior Member
You can't use region for the svyset command - it must be the PSU. I think you have to use region as one of your independent variables in the logit command.
Re: Melogit and Weights [message #19641 is a reply to message #19635] Thu, 23 July 2020 19:48 Go to previous messageGo to next message
Yawo is currently offline  Yawo
Messages: 28
Registered: February 2019
Member
Trevor:

thanks very much for your response. i checked my data and confirmed that dif==1 for all the observations in my data. According to your explanation, this means that the sample weight in this case is not constant within each psu/cluster. However, given that this is the sample weight (v005 or hiv05), shouldn't it be expected to vary among PSU's, as it is a Level 1 (individual level) variable?

My understanding is that all level2 variables should be constant within the level2 grouping ?
Our pseudo level2 weight is set to 1, and therefore constant across all PSU clusters as it should be.

Or what am I missing here? I even checked with an newly downloaded DHS dataset for a single country, and got the same non-constant error?

I would appreciate some further thoughts on this...

Thanks - cY
Re: Melogit and Weights [message #19713 is a reply to message #19641] Wed, 05 August 2020 00:16 Go to previous messageGo to next message
Yawo is currently offline  Yawo
Messages: 28
Registered: February 2019
Member
Mr.Trevor,

good morning. I am following up on the above issue to see if you have any further suggestion as to how to handle the "weights in variable wt not constant within groups defined by: idhspsu"

I am not sure how to make the level 1 weights constant within each psu. At first, I thought it was an issue with my data, but checked with fresh data downloads and got the same error.

I appreciate further thoughts from you. thanks - Yawo
Re: Melogit and Weights [message #19723 is a reply to message #19713] Wed, 05 August 2020 11:14 Go to previous messageGo to next message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 710
Registered: January 2013
Senior Member
Hi Yawo

I think the problem is probably that you do not have a constant value for the weight within level 1. The weight must be constant for all cases in the PSU - it does not vary within PSU. Can you send the code that you are trying to use.
Re: Melogit and Weights [message #19730 is a reply to message #19723] Thu, 06 August 2020 00:40 Go to previous message
Yawo is currently offline  Yawo
Messages: 28
Registered: February 2019
Member
Hi Trevor:

Thanks very much for your assistance. Here is the code I've been using:


/* creating psu and strata for pooled samples/countries */
egen psupool= group(idhspsu sample)
egen stratapool= group(idhsstrata sample)

gen weight=hiv05/1000000
gen weight2=1
svyset psupool, weight(weight) strata(stratapool) singleunit(centered) || _n, weight(weight2)


My data still shows non-constant weights in some of the PSU's

Below is a sample of 4 PSU's from Angola. I checked and many other data (including freshly downloaded versions from DHS) have non-constant weights within PSUs.

Thanks again, and looking forward to any further advice from you.

best - cY


. list sample idhspsu psupool weight weight2 v005 in 200/250

. list sample idhspsu psupool weight weight2 v005 in 200/250
[font=Courier]
     +--------------------------------------------------------------------+
     |      sample      idhspsu   psupool     weight   weight2       v005 |
     |--------------------------------------------------------------------|
200. | Angola 2015   2401000011        11   3.262758         1   2.964534 |
201. | Angola 2015   2401000011        11   2.894893         1   2.836539 |
202. | Angola 2015   2401000011        11   2.894893         1   2.836539 |
203. | Angola 2015   2401000011        11   3.262758         1   2.964534 |
204. | Angola 2015   2401000011        11   3.262758         1   2.964534 |
     |--------------------------------------------------------------------|
205. | Angola 2015   2401000011        11   2.894893         1   2.836539 |
206. | Angola 2015   2401000011        11   2.894893         1   2.836539 |
207. | Angola 2015   2401000011        11   3.262758         1   2.964534 |
208. | Angola 2015   2401000011        11   3.262758         1   2.964534 |
209. | Angola 2015   2401000011        11   3.262758         1   2.964534 |
     |--------------------------------------------------------------------|
210. | Angola 2015   2401000011        11   3.262758         1   2.964534 |
211. | Angola 2015   2401000011        11   3.262758         1   2.964534 |
212. | Angola 2015   2401000011        11   2.894893         1   2.836539 |
213. | Angola 2015   2401000011        11   3.262758         1   2.964534 |
214. | Angola 2015   2401000011        11   2.894893         1   2.836539 |
     |--------------------------------------------------------------------|
215. | Angola 2015   2401000011        11   2.894893         1   2.836539 |
216. | Angola 2015   2401000011        11   2.894893         1   2.836539 |
217. | Angola 2015   2401000011        11   3.262758         1   2.964534 |
218. | Angola 2015   2401000011        11   3.262758         1   2.964534 |
219. | Angola 2015   2401000011        11   2.894893         1   2.836539 |
     |--------------------------------------------------------------------|
220. | Angola 2015   2401000012        12    .396283         1     .41734 |
221. | Angola 2015   2401000012        12     .40295         1    .437145 |
222. | Angola 2015   2401000012        12     .40295         1    .437145 |
223. | Angola 2015   2401000012        12     .40295         1    .437145 |
224. | Angola 2015   2401000012        12    .396283         1     .41734 |
     |--------------------------------------------------------------------|
225. | Angola 2015   2401000012        12    .396283         1     .41734 |
226. | Angola 2015   2401000012        12    .396283         1     .41734 |
227. | Angola 2015   2401000012        12     .40295         1    .437145 |
228. | Angola 2015   2401000012        12    .396283         1     .41734 |
229. | Angola 2015   2401000012        12     .40295         1    .437145 |
     |--------------------------------------------------------------------|
230. | Angola 2015   2401000012        12     .40295         1    .437145 |
231. | Angola 2015   2401000012        12     .40295         1    .437145 |
232. | Angola 2015   2401000012        12     .40295         1    .437145 |
233. | Angola 2015   2401000012        12     .40295         1    .437145 |
234. | Angola 2015   2401000012        12    .396283         1     .41734 |
     |--------------------------------------------------------------------|
235. | Angola 2015   2401000012        12     .40295         1    .437145 |
236. | Angola 2015   2401000012        12    .396283         1     .41734 |
237. | Angola 2015   2401000012        12     .40295         1    .437145 |
238. | Angola 2015   2401000012        12     .40295         1    .437145 |
239. | Angola 2015   2401000013        13    .586726         1    .595693 |
     |--------------------------------------------------------------------|
240. | Angola 2015   2401000013        13    .547652         1    .604053 |
241. | Angola 2015   2401000013        13    .586726         1    .595693 |
242. | Angola 2015   2401000013        13    .547652         1    .604053 |
243. | Angola 2015   2401000013        13    .586726         1    .595693 |
244. | Angola 2015   2401000013        13    .547652         1    .604053 |
     |--------------------------------------------------------------------|
245. | Angola 2015   2401000013        13    .547652         1    .604053 |
246. | Angola 2015   2401000013        13    .586726         1    .595693 |
247. | Angola 2015   2401000013        13    .547652         1    .604053 |
248. | Angola 2015   2401000013        13    .547652         1    .604053 |
249. | Angola 2015   2401000014        14    .503401         1    .477899 |
     |--------------------------------------------------------------------|
250. | Angola 2015   2401000014        14    .465081         1    .491306 |
     +--------------------------------------------------------------------+[/font]

[Updated on: Thu, 06 August 2020 00:42]

Report message to a moderator

Previous Topic: Next IPUMS-DHS Release
Goto Forum:
  


Current Time: Mon Aug 10 01:20:34 Eastern Daylight Time 2020