Home » Data » Merging data files » merge IR MR AND PR (Hypertension in Côte d'Ivoire)
Re: merge IR MR AND PR [message #29026 is a reply to message #28997] |
Fri, 12 April 2024 01:37 |
tanvirpmc04
Messages: 5 Registered: April 2024 Location: Bangladesh
|
Member |
|
|
Dear Tom,
Thank you for your quick response.
I intend to study hypertension which is in PR files, while some associated factors are in IR and MR files. So i plan to merge IR with PR, then merge MR with PR and then append resulting datasets.
Following your advice, i have used these codes:
clear
set maxvar 100000
use " C:\Users\Hp\Desktop\datasets\nepal_dhs\NPIR82DT\NPIR82FL.DTA "
gen sex = "woman"
gen in_IR=1
tab1 in*
gen cluster=v001
gen hh=v002
gen line=v003
save IRtemp.dta, replace
use " C:\Users\Hp\Desktop\datasets\nepal_dhs\NPMR82DT\NPMR82FL.DTA ", clear
gen sex = "man"
gen in_MR=1
tab1 in*
gen cluster=mv001
gen hh=mv002
gen line=mv003
save MRtemp.dta, replace
use " C:\Users\Hp\Desktop\datasets\nepal_dhs\NPPR82DT\NPPR82FL.DTA "
gen in_PR=1
tab1 in*
gen cluster=hv001
gen hh=hv002
gen line=hvidx
gen hab40=ha40 if hv104==2
replace hab40=hb40 if hv104==1
gen bmi=hab40/100
gen bmic=1 if bmi<18.5
replace bmic=2 if bmi>=18.5 & bmi<25
replace bmic=3 if bmi>=25 & bmi<30
replace bmic=4 if bmi>=30 & bmi<50
label define bmic 1"Underweight" 2"Normal" 3"Overweight" 4"Obese"
label values bmic bmic
save PRtemp.dta, replace
* Merge PR with IR
use PRtemp.dta
merge 1:1 cluster hh line using IRtemp.dta
rename _merge merge_PR_IR
keep if merge_PR_IR==3
save IRPR.dta, replace
* Merge with MR
use PRtemp.dta
merge 1:1 cluster hh line using MRtemp.dta
rename _merge merge_PR_MR
keep if merge_PR_MR==3
save MRPR.dta, replace
* Append
use MRPR.dta
append using IRPR.dta
save IRMRPR.dta, replace
use IRMRPR.dta
tab sex
tab bmic
tab bmic sex
However, the outputs are as follows,
tab sex
sex | Freq. Percent Cum.
------------+-----------------------------------
man | 4,913 24.87 24.87
woman | 14,845 75.13 100.00
------------+-----------------------------------
Total | 19,758 100.00
. tab bmic
bmic | Freq. Percent Cum.
------------+-----------------------------------
Underweight | 993 13.51 13.51
Normal | 4,471 60.81 74.32
Overweight | 1,460 19.86 94.18
Obese | 428 5.82 100.00
------------+-----------------------------------
Total | 7,352 100.00
. tab bmic sex
| sex
bmic | woman | Total
------------+-----------+----------
Underweight | 993 | 993
Normal | 4,471 | 4,471
Overweight | 1,460 | 1,460
Obese | 428 | 428
------------+-----------+----------
Total | 7,352 | 7,352
Can You tell me where I am doing it wrong? Thanks in advance.
[Updated on: Fri, 12 April 2024 01:42] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Thu Nov 28 14:37:34 Coordinated Universal Time 2024
|