Announcement

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

  • Duplicate race values

    I am working with a large dataset that includes a Race/Ethnicity variable (ePatient_14). As I merge several years worth of data using a unique id (PcrKey), I have been reshaping each dataset and generating dummy variables to capture each race/ethnicity value. I encountered a problem with the latest year and noted observations within i(PcrKey) with the same value of j(ePatient_14), which are really duplicates. I cannot figure out how to flag these repeated values so I can drop them from the dataset. Does anyone know how to address this without just dropping all duplicate values? Thanks!

    In the example below, ops 118172608 has two values for Race, but they are the same values (which makes it a true duplicate). I need to their be able to flag the duplicate value so I can drop it or I may just have to drop all duplicate values and work with the first/preferred value.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double PcrKey str10 ePatient_14 byte dup
    118172598 "2514005" 0
    118172608 "2514011" 1
    118172608 "2514011" 1
    118172611 "2514011" 0
    118172618 "2514011" 0
    118172621 "2514011" 0
    118172625 "2514011" 0
    118172628 "2514005" 0
    118172629 "2514005" 0
    118172634 "2514005" 0
    118172636 "2514011" 0
    end
    Last edited by Luis Pinet; 01 May 2024, 13:02.

  • #2
    Nevermind... just figured this out. Used the following code to clearly flag observations with duplicate values to allow me to keep the first and drop all others:

    bysort PcrKey ePatient14: gen copies = _n

    If anyone knows a more elegant, easier, or better code to handle these types of problems, please share!

    Comment

    Working...
    X