Forum: Dataset use in Stata
|
Topic: Strange Issues w/ Data Formatting from DHS
|
Re: Strange Issues w/ Data Formatting from DHS [message #29166 is a reply to message #29033] |
Thu, 02 May 2024 08:46 |
tednoel
Messages: 7 Registered: April 2024
|
Member |
|
|
Hi Trevor, I fixed this line of code- thank you so much. Unfortunately, there is still an error cropping up with respect to the hhid case identifier. Below is the lines of code concerned:
use TZWI41FL.dta
sort whhid
save TZWI41FL.dta, replace
use TZPR41FL.dta, clear
* keep the variables you want from the PR file
clonevar whhid = hhid
keep hhid hv005 hv007 hv025 hv219
sort hhid
merge m:1 hhid using TZWI41FL.dta
clonevar v001 = hv001
clonevar v002 = hv002
clonevar v003 = hvidx
sort v001 v002 v003
save TZPR41FL_temp.dta
use TZIR41FL.dta, clear
sort v001 v002 v003
merge 1:1 v001 v002 v003 using TZPR41FL_temp.dta
Unfortunately, it seems like the wealth index cannot be emrged using either "hhid" or "whhid," as I've received error messages for both iterations of this code (attached in photos). I've been trying to figure out what the issue is and perhaps I shouldn't be using the command "clonevar" and perhaps I should just be renaming the variable entirely? I want to make sure that this is correct.
As always, really grateful for your assistance!
|
|
|
Re: Strange Issues w/ Data Formatting from DHS [message #29167 is a reply to message #29166] |
Thu, 02 May 2024 10:03 |
Trevor-DHS
Messages: 793 Registered: January 2013
|
Senior Member |
|
|
Hi
The problem is that hhid does not exist in the WI file, but whhid does. You had the right idea when you created whhid in the PR data using the clonevar statement, but then you dropped it immediately by not including it in the keep statement. So you need to include whhid in the keep statement and then use it in the next few statements as follows:
use TZPR41FL.dta, clear
* keep the variables you want from the PR file
clonevar whhid = hhid
keep whhid hhid hv005 hv007 hv025 hv219
sort whhid
merge m:1 whhid using TZWI41FL.dta
|
|
|