I merged m:1 a BP dataset with BP and heart rate variables with a demographic dataset with age, gender, and education variables (code below). Afterward, in my new merged file, I have repeated observations of the age, gender, and education variables as shown in the data example below. I would like to know what I am doing wrong in this merge process so I can fix it such that I (1) do not have repeated observations of the demographic variables or (2) figure out a way to examine my data as in a Table 1 or analyze my data e.g. in mixed-level models such that I am not using the repeated observations of age and gender in my analysis. Should I have done it the other way round and merged 1:m with the BP dataset being the using file.
Here is the code I used in merging:
Code:
use "/Volumes/Datasets/BP Data/BP.dta" merge m:1 id visit using "/Volumes/Datasets/Demographic Data/Demo.dta" drop _merge save "/Volumes/Datasets/Merged Datasets/Demo_BP_merged.dta", replace
Here is the sample of the merged dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long id byte age str6 gender float education int bp float map int hr double(time datetime) float visit 1 61 "Female" 1 113 88 60 82800000 1.8498204e+12 0 1 61 "Female" 1 129 91 78 32400000 1.84977e+12 0 1 61 "Female" 1 84 61 69 68400000 1.849806e+12 0 1 61 "Female" 1 131 95 73 70380000 1849807980000 0 1 61 "Female" 1 104 76 59 12600000 1.8498366e+12 0 1 61 "Female" 1 112 78 69 79200000 1.8498168e+12 0 1 61 "Female" 1 136 99 65 27540000 1849765140000 0 1 61 "Female" 1 117 81 76 54000000 1.8497916e+12 0 1 61 "Female" 1 117 93 61 84600000 1.8498222e+12 0 1 61 "Female" 1 110 79 85 52380000 1849789980000 0 1 61 "Female" 1 123 80 62 7320000 1849831320000 0 1 61 "Female" 1 119 86 81 55800000 1.8497934e+12 0 1 61 "Female" 1 95 68 61 19800000 1.8498438e+12 0 1 61 "Female" 1 99 71 57 18120000 1849842120000 0 1 61 "Female" 1 117 78 73 41400000 1.849779e+12 0 1 61 "Female" 1 125 92 74 66600000 1.8498042e+12 0 1 61 "Female" 1 111 83 58 1800000 1.8498258e+12 0 1 61 "Female" 1 123 86 70 72000000 1.8498096e+12 0 1 61 "Female" 1 112 84 61 16200000 1.8498402e+12 0 1 61 "Female" 1 98 73 60 81000000 1.8498186e+12 0 1 61 "Female" 1 104 83 67 37800000 1.8497754e+12 0 1 61 "Female" 1 98 68 80 45000000 1.8497826e+12 0 1 61 "Female" 1 103 72 69 61200000 1.8497988e+12 0 1 61 "Female" 1 112 50 54 43200000 1.8497808e+12 0 1 61 "Female" 1 105 83 125 180000 1849824180000 0 1 61 "Female" 1 122 94 77 64980000 1849802580000 0 1 61 "Female" 1 93 57 74 73800000 1.8498114e+12 0 1 61 "Female" 1 102 75 57 3600000 1.8498276e+12 0 1 61 "Female" 1 88 65 74 75600000 1.8498132e+12 0 1 61 "Female" 1 96 72 61 77400000 1.849815e+12 0 1 61 "Female" 1 89 68 60 9000000 1.849833e+12 0 1 61 "Female" 1 98 62 77 59400000 1.849797e+12 0 1 61 "Female" 1 101 68 60 10800000 1.8498348e+12 0 1 61 "Female" 1 112 79 63 14400000 1.8498384e+12 0 1 61 "Female" 1 117 83 57 5400000 1.8498294e+12 0 1 61 "Female" 1 110 81 74 57600000 1.8497952e+12 0 1 61 "Female" 1 89 74 71 46980000 1849784580000 0 1 . "" . 115 86 66 11339999.99975586 1859684939999.9998 1 1 . "" . 112 86 75 83520000 1859670720000 1 1 . "" . 112 73 70 85140000 1859672340000 1 1 . "" . 125 83 76 76139999.99975586 1859663339999.9998 1 1 . "" . 111 83 65 6120000.000244141 1859679720000.0002 1 1 . "" . 101 73 64 63540000 1859650740000 1 1 . "" . 124 91 63 38760000 1859625960000 1 1 . "" . 81 54 66 4140000 1859677740000 1 1 . "" . 113 78 72 2340000 1859675940000 1 1 . "" . 121 93 78 58320000 1859645520000 1 1 . "" . 103 75 66 16739999.99975586 1859690339999.9998 1 1 . "" . 116 84 67 50940000 1859638140000 1 1 . "" . 105 78 71 7740000 1859681340000 1 1 . "" . 98 70 61 22139999.99975586 1859695739999.9998 1 1 . "" . 98 63 72 81539999.99975586 1859668739999.9998 1 1 . "" . 95 61 71 79740000 1859666940000 1 1 . "" . 121 93 79 74520000 1859661720000 1 1 . "" . 96 67 73 47340000 1859634540000 1 1 . "" . 107 70 68 52920000 1859640120000 1 1 . "" . 100 65 62 23940000 1859697540000 1 1 . "" . 101 75 95 67140000 1859654340000 1 1 . "" . 112 75 67 78120000 1859665320000 1 1 . "" . 128 93 60 38580000 1859625780000 1 1 . "" . 118 91 71 9540000 1859683140000 1 1 . "" . 107 72 72 49139999.99975586 1859636339999.9998 1 1 . "" . 101 68 66 45540000 1859632740000 1 1 . "" . 102 71 62 25740000 1859699340000 1 1 . "" . 113 81 60 68940000 1859656140000 1 1 . "" . 120 90 60 38700000 1.8596259e+12 1 1 . "" . 113 85 64 61740000 1859648940000 1 1 . "" . 99 69 58 20340000 1859693940000 1 1 . "" . 91 60 71 65339999.99975586 1859652539999.9998 1 1 . "" . 100 68 65 539999.9997558594 1859674139999.9998 1 1 . "" . 125 93 79 43739999.99975586 1859630939999.9998 1 1 . "" . 137 98 88 41940000 1859629140000 1 1 . "" . 100 79 91 70920000.00024414 1859658120000.0002 1 1 . "" . 111 78 69 13140000 1859686740000 1 1 . "" . 112 71 61 15120000 1859688720000 1 1 . "" . 118 86 75 59939999.99975586 1859647139999.9998 1 2 55 "Female" 1 117 87.52 73 51360000 1877609760000 0 2 55 "Female" 1 91 62.19 72 2760000 1877647560000 0 2 55 "Female" 1 121 90.85 73 49800000 1.8776082e+12 0 2 55 "Female" 1 118 87.85 71 31560000 1877676360000 0 2 55 "Female" 1 121 94.2 74 33360000 1877678160000 0 2 55 "Female" 1 120 85.16 69 35160000 1877679960000 0 2 55 "Female" 1 110 85.21 83 65760000 1877624160000 0 2 55 "Female" 1 113 84.86 74 53160000 1877611560000 0 2 55 "Female" 1 113 89.55 80 29940000 1877674740000 0 2 55 "Female" 1 104 77.87 72 85560000 1877643960000 0 2 55 "Female" 1 139 97.46 71 40560000 1877685360000 0 2 55 "Female" 1 125 93.51 72 42360000 1877600760000 0 2 55 "Female" 1 103 76.2 75 8160000 1877652960000 0 2 55 "Female" 1 99 72.2 60 18960000 1877663760000 0 2 55 "Female" 1 90 69.9 72 9960000 1877654760000 0 2 55 "Female" 1 106 81.88 74 960000 1877645760000 0 2 55 "Female" 1 127 92.16 82 38940000 1877683740000 0 2 55 "Female" 1 98 72.54 69 24360000 1877669160000 0 2 55 "Female" 1 109 85.55 70 38760000 1877597160000 0 2 55 "Female" 1 101 73.53 78 83940000 1877642340000 0 2 55 "Female" 1 112 89.89 69 38940000 1877597340000 0 2 55 "Female" 1 119 90.86 78 74760000 1877633160000 0 2 55 "Female" 1 114 99.26 87 71340000 1877629740000 0 2 55 "Female" 1 126 93.84 92 73140000 1877631540000 0 end format %tc_HH:MM time format %tcNN-DD-CCYY_HH:MM:SS datetime label values id id label values education education label def education 1 "College", modify label values visit visit label def visit 0 "0: Baseline", modify label def visit 1 "1: Follow-up", modify
Thank you
0 Response to Merging m:1 creates repeated observations
Post a Comment