Announcement

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

  • Compare variable in two stata files and list

    I have two datasets and I want to make sure that the same IDnumber has not been recorded twice in the two different data sets (They are two different stata files). See example below. Variable name is IDnumber. How can I ask stata to highlight where the same IDnumber has been recorded twice. for example in this data set, IDnumber 1 and 3 have been recorded twice and I would like stata to list these for me.
    Eg.
    Dataset1
    IDnumber
    1
    2
    3
    4
    5

    Dataset2
    IDnumber
    1
    3
    6
    7
    8

    Thanks very much
    Last edited by Yehani Wedatilake; 11 Oct 2021, 03:05.

  • #2
    Yehani:
    welcome to this forum.
    I would -append- the two files first.
    Then I would type:
    Code:
    sort id
    and eventually I would call:
    Code:
    duplicates list id
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      an alternative: merge the two data sets; the value of the automatically generated _merge variable will tell you whether an id is in both file or, if only one file, which file it is from; see
      Code:
      help merge

      Comment


      • #4
        Originally posted by Rich Goldstein View Post
        an alternative: merge the two data sets; the value of the automatically generated _merge variable will tell you whether an id is in both file or, if only one file, which file it is from; see
        Code:
        help merge
        Thanks this works too

        Comment


        • #5
          Originally posted by Carlo Lazzaro View Post
          Yehani:
          welcome to this forum.
          I would -append- the two files first.
          Then I would type:
          Code:
          sort id
          and eventually I would call:
          Code:
          duplicates list id
          Thank you for this. It works !

          Comment

          Working...
          X