The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Countries » Nepal » Merging data sets for DHS 2011 for Nepal
Re: Merging data sets for DHS 2011 for Nepal [message #3037 is a reply to message #3027] Mon, 06 October 2014 13:38 Go to previous messageGo to previous message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 805
Registered: January 2013
Senior Member
I think there is a much easier way of doing this. You don't need to create a file with migrants as your unit of analysis. See the below code:

use "NPHR60FL.dta"
* Rename variable to drop 0 to allow forvalues below to work
rename sh27_0* sh27_*
rename sh28c_0* sh28c_*

* Initialize to code 2
gen var1=2
* Loop through all migrants and set to var1 if any meet the condition.
forvalues x = 1/16 {
  replace var1=1 if sh21==1 & sh27_`x'==1 & sh28c_`x'>=2
}

* rename variables for matching
rename hv001 v001
rename hv002 v002
keep v001 v002 var1
sort v001 v002
save "var1.dta"

* open IR file and merge
use "NPIR60FL.dta", clear
merge m:1 v001 v002 using "var1.dta"
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: CMC for question s303 in DHS 2011 "how long have you lived apart from your husband"
Next Topic: Merging Nepal DHS data sets across years
Goto Forum:
  


Current Time: Wed Feb 26 03:09:04 Coordinated Universal Time 2025