Announcement

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

  • Getting those records which don't match a regex pattern

    Dear sirs,
    I'm using Stata18 for Mac (Intel 64-bit)
    I've been able to get a substring from string variables through regex and to report it in a new variable with the following code:
    Code:
    generate match = regexs(2) if regexm(varname, regex_pattern)
    It worked very well in returning the substrings and also output that there were 33,214 missing values generated.
    Is there any way to retrieve these records?
    Thank you in advance for your support and availability
    Last edited by Mattia Di Segni; 29 Dec 2024, 16:34.

  • #2
    'Retrieve' is ambiguous, but if you simply want to browse through these observations:

    Code:
    browse varname if missing(match)
    To keep them:



    Code:
    keep if missing(match)

    Comment


    • #3
      Dear Andrew,
      I thank you for your suggestions. Is there any mean to store them on a new variable?

      Comment


      • #4
        Either

        Code:
        gen wanted1= varname if missing(match)
        or use the negation operator with your regex command

        Code:
        generate wanted2 = varname if !regexm(varname, regex_pattern)
        See

        Code:
        help operators

        Comment

        Working...
        X