Announcement

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

  • Keeping only the first observation

    Dear Stata Users,

    I have a small challenge. I have enormous data with repeating information. I would like to keep only the first row per ID. Here is sample data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int ID
    1
    1
    1
    1
    1
    1
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    3
    3
    3
    3
    3
    3
    4
    4
    4
    4
    4
    4
    5
    5
    5
    5
    5
    5
    6
    6
    6
    6
    6
    6
    6
    6
    7
    7
    end
    In this case, I would like to have only one row per ID, in the end, I would like to only have seven rows. Thanks for your help!


  • #2
    Maxwell:
    you may want to try:
    Code:
    bysort ID: keep if _n==1
    As usual, remember to save your original dataset beforehand.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thanks a lot Carlo for your support!

      Comment

      Working...
      X