The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Countries » Kenya » Merging IR and MR Kenya 2022 (2022 KDHS) (Chronic Disease)
Merging IR and MR Kenya 2022 (2022 KDHS) [message #28346] Mon, 18 December 2023 16:04 Go to next message
bakerchowdhury
Messages: 25
Registered: April 2014
Member
Hello everyone,
I am analyzing 2022 Kenya DHS. To do all women and men as unit of analysis I would like to add the women (IR) and men's (MR) data together. The IR file has straightforward DHS variable names, however; the MR files has an 'm' added in the beginning of each variables.

I have used the below Stata code.

*mens recode
use "KEMR8BFL", replace
rename (mv001 mv002 mv003 mv005) (v001 v002 v003 v005)
sort v001 v002 v003
save "MRtemp.dta", replace

*individual recode
use "KEIR8BFL", clear
sort v001 v002 v003

merge v001 v002 v003 using "MRtemp.dta"

However, this code doesn't combine the data appropriately. What would be best approach to keep same variable names for both men and women by creating a sex variable and use survey weights appropriately?

The goal is to analyze the chronic disease indicators (chapter 14) primarily by gender and other characteristics. Although I have successfully replicated the Chapter 14 tables separately by sex, I am facing difficulty in consolidating them into one data file so that I can achieve my analysis goal.

I would greatly appreciate your insights and recommendations on the most efficient approach to address this issue.
Thank you for your time and assistance.
Best regards,


Thank you!
Muhammad
Re: Merging IR and MR Kenya 2022 (2022 KDHS) [message #28354 is a reply to message #28346] Tue, 19 December 2023 08:17 Go to previous messageGo to next message
sokiya is currently offline  sokiya
Messages: 78
Registered: May 2017
Location: Nairobi
Senior Member
I believe what you want to do is an append and not merge. Having said that, it will also require renaming of variables in the MR file by removing the m prefix.
Hope it helps!
Re: Merging IR and MR Kenya 2022 (2022 KDHS) [message #28357 is a reply to message #28354] Tue, 19 December 2023 14:03 Go to previous messageGo to next message
bakerchowdhury
Messages: 25
Registered: April 2014
Member
Thank you Sokiya, for your input. But my goal is to create a "gender" variable. How can we achieve that?
Re: Merging IR and MR Kenya 2022 (2022 KDHS) [message #28358 is a reply to message #28357] Wed, 20 December 2023 01:05 Go to previous messageGo to next message
sokiya is currently offline  sokiya
Messages: 78
Registered: May 2017
Location: Nairobi
Senior Member
I would use the following code with an assumption that the variables in IR and MR are similar with an exception of the m prefix in the MR file

*mens recode
use "KEMR8BFL", replace
* Drop variables that will cause problems in renaming. You can handle them better!
drop m304a*
* Remove m prefix
renpfix m

tempfile MRtemp
save `MRtemp'


*individual recode
*use "KEIR8BFL", clear
* Generate gender variable
gen gender = 2
append using `MRtemp'
replace gender = 1 if mi(gender)
lab def gender 1 "Male" 2 "Female"
lab val gender gender
ta gender

Let me know in case of further questions
Re: Merging IR and MR Kenya 2022 (2022 KDHS) [message #28360 is a reply to message #28358] Wed, 20 December 2023 13:00 Go to previous message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 3196
Registered: February 2013
Senior Member
Following is a response from Senior DHS staff member, Tom Pullum:

This is not a case-by-case merge. You need to "append" the files. The following Stata lines should work, although you may have to modify them somewhat. For example, in this survey the DV variables for women have the prefix "d", but the DV variables for men have the prefix "sdm" rather than "md", so I include a special line for them. It is possible that other variables need special re-naming.

use "KEMR8BFL", clear
gen sex=1
rename m* *
rename sdm* d*

append using "KEIR8BFL"
replace sex=2 if sex==.

label define sex 1 "Men" 2 "Women"
label values sex sex
Previous Topic: KDHS 2022: Table 5.10 Age at first birth
Next Topic: Knowing the exact date of interview
Goto Forum:
  


Current Time: Mon Nov 18 07:22:10 Coordinated Universal Time 2024