Announcement

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

  • How to select/identify observations based on the absence of a specific word in a string variable

    Hi,
    I want to select observations based on the absence of a single word of a string variable. for example: if I have a variable indicating multiple answers like "a b c", I want to identify all observations that does not include "c". Example

    # answers
    1 a b c d
    2 a b d
    3 a c d
    4 a d

    I need a code to identify the observations "2" and "4". I know the "strpos()" function that helps identifying observation with a certain element, but I'm not sure if it can be used to identify observations that misses a certain element.

    Thank you in advance

  • #2
    The negation operator is

    Code:
    !
    or

    Code:
    ~
    See

    Code:
    help operators
    So you can write an expression of the form

    Code:
    !strpos(...) ...

    Comment


    • #3
      It worked. Thanks a lot

      Comment

      Working...
      X