|
2 | 2 | Program: mergeHW.do |
3 | 3 | Purpose: example shown to merge HW to PR file. Notes given on how to merge with other files. |
4 | 4 | Author: Shireen Assaf |
5 | | -Date last modified: May 27, 2021 by Shireen Assaf |
| 5 | +Date last modified: July 31, 2023 by Shireen Assaf |
6 | 6 |
|
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. |
8 | 8 | 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. |
10 | 10 | *****************************************************************************************************/ |
11 | 11 |
|
12 | 12 | *For HW files that have hwhhid |
@@ -37,42 +37,38 @@ erase HWtemp.dta |
37 | 37 | *Open HW file |
38 | 38 | use BDHW41FL.dta, clear |
39 | 39 |
|
| 40 | +*creating unique identifier variables from hwcaseid |
| 41 | + |
40 | 42 | gen hhid =substr(hwcaseid,1,12) |
41 | 43 | gen hvidx=substr(hwcaseid,13,3) |
42 | 44 | destring hvidx, replace |
43 | | -gen hwidx=hvidx |
44 | 45 |
|
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) |
49 | 48 |
|
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 |
54 | 51 |
|
55 | | -sort state_id cluster_id household_id hvidx |
| 52 | +sort cluster_id household_id hvidx |
56 | 53 | save HWtemp.dta, replace |
57 | 54 |
|
58 | 55 |
|
59 | 56 | *Open PR file |
60 | 57 | use BDPR41FL.dta, clear |
61 | 58 |
|
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 |
66 | 64 |
|
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 |
72 | 66 |
|
73 | 67 | *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" |
75 | 69 |
|
76 | 70 | *Erase temporary file |
77 | 71 | erase HWtemp.dta |
78 | 72 |
|
| 73 | + |
| 74 | + |
0 commit comments