The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Merging data files » Couples and HIV merge in STATA
Couples and HIV merge in STATA [message #3271] Sat, 15 November 2014 19:47 Go to next message
DaniD is currently offline  DaniD
Messages: 13
Registered: November 2014
Member
Hi, does anyone happen to have the code or can help with merging the couples dataset with the HIV dataset in STATA? Thank you! ---Dani
Re: Couples and HIV merge in STATA [message #3284 is a reply to message #3271] Mon, 17 November 2014 18:22 Go to previous messageGo to next message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 805
Registered: January 2013
Senior Member
You have to do this twice. Once for women and then once for men. Here is how to merge the AR file with the CR file for women first:

* Step 1: open AR file
use "xxAR61FL.DTA", clear

* Step 2: rename identifying variables
renvars hivclust hivnumb hivline / v001 v002 v003

* Step 3: sort by identifying variables
sort v001 v002 v003

* Step 4: save results
save "xxAR61FL_mergeprep.DTA", replace

* Step 5: open IR file
use "xxCR61FL.DTA", clear

* Step 6: sort by identifying variables
sort v001 v002 v003

* Step 7: merge!
merge v001 v002 v003 using "xxAR61FL_mergeprep.DTA"

* Step 8: Keep only women
drop if _merge==2

Then rename the added hiv variables to something unique for women, e.g.
rename hiv* w_hiv*

and repeat steps 1-8 above using mv003 instead of v003 throughout to merge the men's hiv test result and then finally rename the hiv variables to be for men, e.g.
rename hiv* m_hiv*
Re: Couples and HIV merge in STATA [message #3294 is a reply to message #3284] Tue, 18 November 2014 15:39 Go to previous messageGo to next message
DaniD is currently offline  DaniD
Messages: 13
Registered: November 2014
Member
Thank you so much Trevor! So now I'm trying to figure out how to match the men with the women (as couples). Is there a variable that uniquely identifies partners that I can use to merge the datasets? It looks like the household number does not capture this. Thanks much!
Re: Couples and HIV merge in STATA [message #3295 is a reply to message #3294] Tue, 18 November 2014 17:20 Go to previous messageGo to next message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 805
Registered: January 2013
Senior Member
If you use the Couples Recode (CR) file, they are already matched.

If you want to redo the merging use the following variables:
Women's Recode (IR) file: v001 v002 and v034 (partner's line number)
Men's Recode (MR) file: mv001 mv002 and mv003
Re: Couples and HIV merge in STATA [message #9536 is a reply to message #3271] Mon, 11 April 2016 01:01 Go to previous message
lberes
Messages: 4
Registered: April 2016
Member
Thank you for this helpful code. I am wondering why drop if _merge==2 allows us to 'keep only women'. I thought that any combination of v001, v002 and v003 that came from either the couples or the HIV data could only be a woman. How does dropping that combination if it only came from the HIV dataset - and was not in the couples data set - exclude men? In other words, what does drop if _merge==2 do for us in this code? Thank you!
Previous Topic: Mother's and Father's occupation
Next Topic: Merging Birth and Household Recodes
Goto Forum:
  


Current Time: Sun Dec 22 16:48:59 Coordinated Universal Time 2024