The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Merging data files » Merge WI to KR in Mali
Re: Merge WI to KR in Mali [message #17925 is a reply to message #17898] Thu, 18 July 2019 09:42 Go to previous messageGo to previous message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 3035
Registered: February 2013
Senior Member
Following is a response from DHS Research & Data Analysis Director, Tom Pullum:

Merges involving these two surveys in Mali are difficult because they included a "sub-household" code. Fortunately, the subsequent surveys in Mali did not have this complication. (A couple of non-Mali surveys have the same problem.)

However, for what you want to do, you can bypass the HR file completely. You can merge the WI and KR files directly. It helps that the wealth index is the same for all sub-households within a household so you don't have to distinguish the sub-households. For some other merges with these surveys, you do need to do that.

The following lines show how to do this with the 1995-96 survey. You will have to change the paths. The basic strategy is to use the household id code. First you need to unpack the columns of whhid in the WI file and caseid in the KR file. I find that columns 1-12 of caseid are a match with columns 1-12 of whhid. This "unpacking" strategy will virtually always work for a merge that is giving you a problem.


* Procedure to transfer the wealth index from WI to KR without using HR

use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\MLWI32FL.DTA", clear 
describe whhid
list if _n<=20, table clean


* I want to identify the separate columns of whhid
local li=1
while `li'<=12 {
gen str1 col`li'=substr(whhid,`li',1)
local li=`li'+1
}

list whhid col* if _n<20, table clean


use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\MLKR31FL.DTA", clear 
describe caseid
list caseid if _n<=20


* I want to identify the separate columns of caseid
local li=1
while `li'<=15 {
gen str1 col`li'=substr(caseid,`li',1)
local li=`li'+1
}

list caseid col* if _n<20, table clean

* It appears that columns 1-12 of caseid in the KR file match with columns 1-12 of whhid in the WI file


* Now do the merge

use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\MLWI32FL.DTA", clear 
gen mergeid=whhid
sort mergeid
save e:\DHS\DHS_data\scratch\MLWItemp.dta, replace

use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\MLKR31FL.DTA", clear 
gen mergeid=substr(caseid,1,12)
sort mergeid

merge mergeid using e:\DHS\DHS_data\scratch\MLWItemp.dta
tab _merge
keep if _merge==3
drop _merge

summarize wlthind*

 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Merging BR file with PR file for NFHS-4 round(India)
Next Topic: Merging of NFHS-4 dataset
Goto Forum:
  


Current Time: Sat Apr 20 02:26:58 Coordinated Universal Time 2024