Announcement

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

  • keep observations depending on the first letter of a string variable

    Hi, I have a set of categorical variables from a census data and I am trying to extract/keep observations with a forward sortation area starting with the letters K, L, M, N and P. The variable name for the forward sortation Is geo_name

    I keep getting an "options not allowed" error. Here is the code I used:

    keep if substr(geo_name, 1, 1)== "L", "K", "M", "N", "P"


    It's able to extract observations with a forward sortation areas starting with "L" using keep if substr(geo_name, 1, 1)== "L" ; but it does not work once I add another letter so I can extract other forward sortation areas beginning with the letters K, M, N and P as well

    Can anyone help me figure out what I am doing wrong?

    Thanks in advance!

  • #2
    Code:
    keep if inlist(substr(geo_name, 1, 1),"L", "K", "M", "N", "P")

    Comment

    Working...
    X