Announcement

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

  • forvalues command for specific values of a variable

    Hi all,

    my problem is, that i´d like to delete just specific duplicates of a variable, but not all duplicates. Of course I could do it with repeatedly typing "duplicates drop if var_xy == x1" for all values
    but I´m searching for a more elegant solution. I thought about solving it with a forvalues command like:

    forvalues var_xy=1 5 6 9 ... {
    duplicates drop
    }

    But forvalues isn´t working for single digits.

    If anyone has an idea how to solve this problem, please let me know!

    Thanks

    Anna
    Anna Volkert (Arntz)
    Research Associate

    IMVR - Institute für Medical Sociology, Health Service Research and Rehabilitation Science
    Faculty of Human Sciences
    Faculty of Medicine
    University of Cologne

  • #2
    Try

    Code:
    local values "1 5 6 9"
    foreach value of local values {
    duplicates drop if var_xy == `value'
    }

    Comment


    • #3

      First simplification

      Code:
      foreach value in 1 5 6 9  {    
         duplicates drop if var_xy == `value'
      }
      Second simplification

      Code:
      duplicates drop if inlist(var_xy, 1, 5, 6, 9)

      Comment


      • #4
        Perfect! Thanks a lot!
        Anna Volkert (Arntz)
        Research Associate

        IMVR - Institute für Medical Sociology, Health Service Research and Rehabilitation Science
        Faculty of Human Sciences
        Faculty of Medicine
        University of Cologne

        Comment

        Working...
        X