Announcement

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

  • Dropping Entire Row if Variable has a Specific Value

    Hi all,

    This looked like an easy one but I'm stuck. My data contains a variable (let's call this variable 'cratn'). This variable contains text (string) which could be No, Yes, Maybe.
    I want to drop an entire row of data if the value of the variable (cratn) for that row says "No."
    I tried to use

    drop if cratn ==No

    But this returns an error: No not found (r111).

    What am I doing wrong, please?
    Thanks in advance.

  • #2
    Stata is looking for a variable (or scalar) with that name (or with a variable name that abbreviates to that if you allow abbreviations) and it can't find any such.

    As you know, when you specify cratn you're giving a variable name. So also a bare No is expected to be a name, not a value. You need " " to specify that you're talking about is a literal string.

    Code:
    drop if cratn == "No"
    Note that Stata will be literal. " No " "NO" "no" " no " and various other possible values won't qualify.

    Comment


    • #3
      If you have the variety Nick mentions, you can strtrim(cratn) and strlower(cratn) first to clean it up.

      Comment


      • #4
        Dear Nick and George, thank you so much for your helpful comments.
        It's my first post and I'm new to using Stata. I appreciate your assistance.

        Comment

        Working...
        X