Announcement

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

  • Extract data

    Hello

    I have a data for African countries and I want to keep only the data for countries with this code
    COM
    ETH
    KEN


    how I can do this please


  • #2
    this command worked

    keep if country == "COM" | country == "ETH" | country == "KEN" | country == "MUS" | country == "MWI" | country == "ZMB" | country == "ZWE"

    Comment


    • #3
      Yes, that would work. You could also save yourself some typing by doing this instead:
      Code:
      keep if inlist(country, "COM", "ETH", "KEN", "MUS", "MWI", "ZMB", "ZWE")
      With strings, -inlist()- is available to you for up to 9 such countries. If in another situation you had a larger number of countries, you would have to do something more complicated such as breaking them into groups of 9 and then conjoining the separate -inlist()- terms with |.

      Comment


      • #4
        Originally posted by Clyde Schechter View Post
        Yes, that would work. You could also save yourself some typing by doing this instead:
        Code:
        keep if inlist(country, "COM", "ETH", "KEN", "MUS", "MWI", "ZMB", "ZWE")
        With strings, -inlist()- is available to you for up to 9 such countries. If in another situation you had a larger number of countries, you would have to do something more complicated such as breaking them into groups of 9 and then conjoining the separate -inlist()- terms with |.
        Thanks

        Comment

        Working...
        X