Announcement

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

  • how do you drop all data not equal to two values in a column

    I know I can use the drop and keep functions to clean my data, but what happens if I have a column and I just want to keep the data in it that equals two values
    ID country
    1 100
    2 150
    3 802
    4 200
    I want to drop all values that are not equal to either 100 or 200. So that my entire dataset has only countries represented by the numbers 200 and 100. I've tried using the code:

    keep if country==100|200

    But this deletes 0 observations. I tried using the following:

    drop if race!=100 | 200

    And this deleted ALL of the my observations.

    I'm a bit confused here. Any help?

  • #2
    Code:
    keep if country == 100 | country == 200
    or
    Code:
    keep if inlist(country, 100, 200)

    Comment

    Working...
    X