Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Removing Multiple Admissions by ID

    I have a data set that has admission dates by person ID (MRN). I would like to remove multiple admissions within 60 days for an individual keeping the first admission date.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long MRN int AdmissionDate
      2972 20095
      3897 20452
     10173 20378
     26278 20251
     32706 20298
     33589 20228
     44859 20168
     47134 20142
     48637 20196
     48637 20450
     60699 20143
     95513 20335
    113290 20447
    119693 20093
    121764 20356
    138628 20226
    138628 20234
    141747 20169
    144469 20111
    144469 20150
    144469 20235
    144469 20248
    145367 20089
    145367 20293
    145367 20298
    149005 20162
    149005 20235
    151019 20350
    152751 20402
    152751 20408
    154419 20334
    156158 20201
    161737 20408
    162545 20156
    165449 20383
    165449 20389
    165449 20432
    174615 20221
    175158 20231
    179846 20209
    182568 20257
    184044 20313
    186791 20431
    188730 20200
    198986 20248
    200303 20415
    200303 20416
    212159 20317
    213272 20277
    213272 20370
    242826 20122
    257949 20326
    259887 20167
    259887 20185
    263665 20185
    264747 20415
    284315 20263
    284745 20341
    315564 20117
    315564 20141
    315564 20250
    326132 20282
    326132 20296
    332528 20165
    381723 20386
    391391 20291
    391391 20421
    392928 20404
    419861 20177
    429514 20272
    434175 20228
    434175 20246
    462739 20109
    462739 20120
    462739 20151
    462739 20161
    462739 20170
    465989 20424
    465989 20425
    465989 20450
    469957 20231
    479592 20144
    479592 20380
    479592 20439
    481135 20222
    481135 20228
    507921 20323
    519272 20261
    520221 20434
    520221 20440
    538678 20178
    539718 20139
    539718 20195
    544395 20389
    557579 20116
    577163 20249
    577163 20263
    582676 20204
    589358 20324
    589358 20357
    end
    format %td AdmissionDate

  • #2
    Suppose you had a person with exactly three admission dates: May 1 and June 15 (45 days apart) and July 1 (16 days after June 15, 61 days from May 1).

    What date(s) would you keep and what date(s) would you remove?

    Comment


    • #3
      I am sorry i didn't make this clear. I would like to keep May 1 and July 1 but not June 15. Suppose there is a fourth admission date for the same person July 5th, would like to remove that too because its within 60 days of July 1. Hope this makes sense. Thanks!

      Comment


      • #4
        This code, run on your data, seems to do what you want.
        Code:
        generate start60 = AdmissionDate
        format %td start60
        bysort MRN (AdmissionDate): replace start60 = start60[_n-1] if _n>1 & AdmissionDate<start60[_n-1]+60
        generate todrop = AdmissionDate != start60
        list, clean

        Comment

        Working...
        X