The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Merging data files » Merging IR and PR - Indonesia 1987
Merging IR and PR - Indonesia 1987 [message #27982] Tue, 31 October 2023 05:41 Go to previous message
albena is currently offline  albena
Messages: 10
Registered: February 2015
Member
Dear all,

I would like to merge the PR data file with the IR data file for Indonesia 1987. I am struggling with setting up the variables for merging in the PR data. In the IR data those are straightforward - v001 (sprov), v002 and v003.

Here is my Stata code to illustrate what I have so far with the PR data file.


 

use "..../IDHH01FL.dta", clear

gen id = _n

gen wt1 = 1       //generate self-weighting as the hhweight from PR cannot be combined with the wmweight from IR

keep hhage_* hhsex_* hhlno_* hhevm_* hhyear hhprov hhreg hhkeyer hhsamp hhsampno wt1 id            // no variable on whether hh member slept there last night -> difficult to reconstruct the sample of eligible women for the women's interview


foreach num of numlist 1/9 {

rename hhage_0`num' hhage_`num' 

}

foreach num of numlist 1/9 {

rename hhsex_0`num' hhsex_`num' 

}

foreach num of numlist 1/9 {

rename hhlno_0`num' hhlno_`num' 

}

foreach num of numlist 1/9 {

rename hhevm_0`num' hhevm_`num' 

}

reshape long hhage_ hhsex_ hhlno_ hhevm_, i(id) j(member)  

drop if hhage_ ==. & hhsex_ ==. & hhlno_ ==. & hhevm_==.

keep if hhsex_ ==2

keep if hhage_ >=15 & hhage_ <=49

rename hhprov prov

rename hhsamp v002

rename hhlno_ v003

sort prov v002 v003

order prov v002 v003 member

save "..../IndonesiaPR1987.dta", replace



***** the IR data

use ".../IDIR01FL.dta", clear

keep v001 v002 v003 v005 v007 v010 v012 v013 v511 v806 sprov

gen wt=v005/1000000
 
rename v012 current_age

rename sprov prov

sort prov v002 v003

save ".../IndonesiaIR1987.dta", replace


**** Merge PR (master) with IR (using)

use ".../IndonesiaPR1987.dta", clear

merge 1:1 prov v002 v003 using "..../IndonesiaIR1987.dta"




This is the where I get an error message that I have duplicates in the variables for merging from the master data. I am pretty sure that I might have the wrong variables from the PR data for merging, but at this point I don't really which other ones to try or what other combination I could have.

Could you help me with merging these two datasets?

Thank you!

Albena
 
Read Message
Read Message
Previous Topic: weighting of men's data in Nepal DHS 2022 survey
Next Topic: Merging two rounds
Goto Forum:
  


Current Time: Sat Oct 5 07:18:35 Coordinated Universal Time 2024