Merging Household+Female+Male files [message #3575] |
Mon, 12 January 2015 23:19  |
UAB_user
Messages: 21 Registered: September 2014 Location: Alabama
|
Member |
|
|
Hello,
I am looking at male migration in the 2011 Nepal DHS and I want to merge the female file (IR) with the household file (HR) and then merge this to the male file (MR). I know you have to match the male and female files on V001 + V002 + V003 and then match that new data set to the household file using V001 + V002, like what is recommended on the DHS web page, but I am not sure if I did it right since the final number for each merge do not seem to add up.
The Household file has 10826 observations and the female file has 12674 observations. When I merge them with the following SAS code I get 14588 observations.
data derek.full2011;
merge derek.nphr60fl (in=a) derek.npir60fl (in=b) ; by V001 V002 ; run;
The male file has 4121 observations in it and when I merge it into the file above (14588 obs) using the following SAS code I get 18709 observations, which I think means none of the male file merged into my household + female files
data derek.full2011b;
merge derek.full2011 (in=a) derek.npmr60fla (in=b); by V001 V002 V003;
run;
Thank you for the help
Derek
|
|
|
Re: Merging Household+Female+Male files [message #3834 is a reply to message #3575] |
Fri, 20 February 2015 20:01  |
Liz-DHS
Messages: 1516 Registered: February 2013
|
Senior Member |
|
|
Dear User,
Here is a response from one of our experts, Dr. Tom Pullum:
Quote:I would use the following sequence, in Stata terminology (I do not use SAS). First, in the male file, rename the mv* variables to be v*. Then append one file to the other. This is not a merge, it is an append. Then rename v001 to be hv001, v002 to be hv002, and v003 to be hvidx. Then sort the combined file on hv001, hv002, hvidx. Save with a temporary file name such as "IR_MR_temp.dta". Then open the PR file, NOT the HR file, and sort it by hv001, hv002, hvidx. Then merge with "IR_MR_temp.dta". Then save cases that are in both files. Good luck!
|
|
|