Skip to content

Commit f7c776b

Browse files
committed
updates and fixes
1 parent 70cb426 commit f7c776b

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

Intro_DHSdata_Analysis/4_Using_Multiple_Files/Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The code also shows how to append the merged IR and MR files to a dataset that c
2626
### mergeHW
2727
Older datasets may not contain the anthropometry variables according to the WHO reference.
2828
HW files are created with the WHO reference nutrition indicators that can be merged to datasets.
29-
Here we show an example using the Bangladesh 1999-2000 survey since there is no HW file for model datasets.
29+
Here we show an example using the Bangladesh 1999-2000 and the 2004 surveys since there is no HW file for model datasets.
3030

3131
### mergeWI
3232
Older datasets sometimes do not contain the wealth index.

Intro_DHSdata_Analysis/4_Using_Multiple_Files/mergeHW.do

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Program: mergeHW.do
33
Purpose: example shown to merge HW to PR file. Notes given on how to merge with other files.
44
Author: Shireen Assaf
5-
Date last modified: May 27, 2021 by Shireen Assaf
5+
Date last modified: July 31, 2023 by Shireen Assaf
66
7-
Notes: Older datasets may not contian the anthropometry variables according to the WHO reference.
7+
Notes: Older datasets may not contain the anthropometry variables according to the WHO reference.
88
HW files are created with the WHO reference nutrition indicators that can be merged to datasets.
9-
Will use two Bangladesh survey as examples since model datasets do not have an HW file.
9+
Will use two Bangladesh surveys as examples since model datasets do not have an HW file.
1010
*****************************************************************************************************/
1111

1212
*For HW files that have hwhhid
@@ -37,42 +37,38 @@ erase HWtemp.dta
3737
*Open HW file
3838
use BDHW41FL.dta, clear
3939

40+
*creating unique identifier variables from hwcaseid
41+
4042
gen hhid =substr(hwcaseid,1,12)
4143
gen hvidx=substr(hwcaseid,13,3)
4244
destring hvidx, replace
43-
gen hwidx=hvidx
4445

45-
gen hwcol_1to3=substr(hhid,1,3)
46-
gen hwcol_4to5=substr(hhid,4,2)
47-
gen hwcol_6to8=substr(hhid,6,3)
48-
gen hwcol_9to12=substr(hhid,9,4)
46+
gen cluster_id=substr(hhid,6,3)
47+
gen household_id=substr(hhid,9,4)
4948

50-
destring hwcol*to*, replace
51-
gen state_id=hwcol_4to5
52-
gen cluster_id=hwcol_6to8
53-
gen household_id=hwcol_9to12
49+
destring cluster_id, replace
50+
destring household_id, replace
5451

55-
sort state_id cluster_id household_id hvidx
52+
sort cluster_id household_id hvidx
5653
save HWtemp.dta, replace
5754

5855

5956
*Open PR file
6057
use BDPR41FL.dta, clear
6158

62-
gen hvcol_1to3=substr(hhid,1,3)
63-
gen hvcol_4to5=substr(hhid,4,2)
64-
gen hvcol_6to8=substr(hhid,6,3)
65-
gen hvcol_9to12=substr(hhid,9,4)
59+
gen cluster_id=substr(hhid,6,3)
60+
gen household_id=substr(hhid,9,4)
61+
62+
destring cluster_id, replace
63+
destring household_id, replace
6664

67-
destring hvcol*to*, replace
68-
gen state_id=hvcol_4to5
69-
gen cluster_id=hvcol_6to8
70-
gen household_id=hvcol_9to12
71-
sort state_id cluster_id household_id hvidx
65+
sort cluster_id household_id hvidx
7266

7367
*Perform the merge
74-
merge state_id cluster_id household_id hvidx using "HWtemp.dta"
68+
merge cluster_id household_id hvidx using "HWtemp.dta"
7569

7670
*Erase temporary file
7771
erase HWtemp.dta
7872

73+
74+

Intro_DHSdata_Analysis/4_Using_Multiple_Files/mergeWI.do

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ Purpose: example shown to merge WR to IR file. Notes given on how to merge wi
44
Author: Shireen Assaf
55
Date last modified: May 27, 2021 by Shireen Assaf
66
7-
Notes: Older datasets sometimes do not contain the wealth index. To include the wealth index, a WI file was created for these surveys. Will use the Bangladesh 1999-2000 survey as an example since model datasets do not have an WI file.
8-
7+
Notes: Older datasets sometimes do not contain the wealth index.
8+
To include the wealth index, a WI file was created for these surveys.
9+
This code will use the Bangladesh 1999-2000 survey as an example since model datasets do not have an WI file.
10+
911
Notes are given at the end of the file on how to perform other merges of WI file with other file types.
1012
*****************************************************************************************************/
1113

0 commit comments

Comments
 (0)