The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Dataset use in Stata » Multilevel modeling in DHS-Sri Lanka
Multilevel modeling in DHS-Sri Lanka [message #16598] Tue, 05 February 2019 08:15 Go to next message
dga1n@soton.ac.uk is currently offline  dga1n@soton.ac.uk
Messages: 9
Registered: March 2018
Location: United Kingdom
Member

Dear DHS specialists,

I need to make a community poverty variable for my multilevel analysis. Hence I generated following command using some tutorials. However when I used bys QACLUST: egen tot_in_clus3=count(QACLUST) command , it comes with the error saying "type mismatch". I need to make community poverty variable with 0 for "low"=percentage who are belongs to middle and above and 1as hight for who are belong to lowest and secondary (all five categories)

QAcluster =Is my cluster ID and QHWEALTH is my wealth index quintiles (five categories)..

gen poverty=0
replace poverty=1 if QHWLTHI<=2
*collapse poverty, by(QACLUST)
bys QACLUST: egen tot_in_clus3=count(QACLUST)
bys QACLUST : egen tot_poverty=total(poverty)
bys QACLUST: gen poverty_percent=tot_poverty*100/tot_in_clus3

gen com_poverty=0
replace com_poverty=1 if poverty_percent > 48.06854
label variable com_poverty "Community poverty"
label define com_poverty 0"low" 1"High"
label values com_poverty com_poverty


Could you kindly help me?

Thanks

Best
Gaya



gayathri
Re: Multilevel modeling in DHS-Sri Lanka [message #16614 is a reply to message #16598] Wed, 06 February 2019 10:09 Go to previous messageGo to next message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 1926
Registered: February 2013
Senior Member
Following is a response from Senior DHS Stata Specialist, Tom Pullum:

"Type" refers to whether the variable is stored as a number or as a string (that is, as characters). In general, you get this error when you accidentally mix numeric and string variables within a command or ask for an operation with a string variable that can only be done with a numeric variable. My guess is that your QACLUST is coded with numbers such as 1, 2, 3, etc., but you have somehow specified those numbers to be read as characters.

The data files already contain a variable that is the cluster id code. It's v001 in the IR and BR and KR files, hv001 in the HR and PR files, and mv001 in the MR file. It's a numeric variable, and your code will work fine if you use it in place of QACLUST.

To repeat, I believe that your QACLUST has been constructed as a string variable and that's the problem. To find out how QACLUST is being interpreted by Stata, enter "describe QACLUST". Good luck.
Re: Multilevel modeling in DHS-Sri Lanka [message #16625 is a reply to message #16614] Thu, 07 February 2019 11:50 Go to previous message
dga1n@soton.ac.uk is currently offline  dga1n@soton.ac.uk
Messages: 9
Registered: March 2018
Location: United Kingdom
Member

Dear Dr.Pullum,

I am grateful for your response. I converted my variables successfully. Thanks


gayathri
Previous Topic: Family structure
Next Topic: Merging Datasets and Matching Observations BDHS 2007
Goto Forum:
  


Current Time: Mon Sep 28 02:35:27 Eastern Daylight Time 2020