Announcement

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

  • How to use ustrregexm for string variable search inclusion/exclusion criteria

    Hi,

    I am attempting to generate a binary variable "weap_firearm" from two string (strL) variables "objetivo" and "subjetivo" which are both variables that contain medical notes from consultations.
    This is the code I am running:

    Code:
    gen weap_firearm =     ustrregexm(subjetivo, "(TIRO.*|ARMA.*|PISTOL.*|ESFAQUEA.*|FACA.*|FERID.* BALA|BALEAD.*|FERID.* FACA)") | ///
                        ustrregexm(objetivo, "(TIRO.*|ARMA.*|PISTOL.*|ESFAQUEA.*|FACA.*|FERID.* BALA|BALEAD.*|FERID.* FACA)") & ///
                        !ustrregexm(subjetivo[-5/5], "(NAMORAD.*|PARCEIR.*|MARIDO|MULHER|ESPOS.*|FAM.*|CONJUGE|COMPANHEIR.*|CONSORTE|DOMESTIC.*|CASA|RESIDENCIA|FAMILIA.*|ESTUPR.*|CONJUGAL|NEGLIG.*|SUSPEIT.*|SEXUAL)") & ///
                        !ustrregexm(objetivo[-5/5], "(NAMORAD.*|PARCEIR.*|MARIDO|MULHER|ESPOS.*|FAM.*|CONJUGE|COMPANHEIR.*|CONSORTE|DOMESTIC.*|CASA|RESIDENCIA|FAMILIA.*|ESTUPR.*|CONJUGAL|NEGLIG.*|SUSPEIT.*|SEXUAL)") & ///
                        !ustrregexm(subjetivo, "(TIROIDE|LEVOTIROXINA|TIRO DUVIDAS|REFACA|FARMACIA|RETIROU|DIALEVOTIROXINA|FARMACOS|TUMEFACAO|FARMACEUTICO|FARMACOLOGICO|ALARMA|TIROU|RETIRO|AFERIDA)") & ///
                        !ustrregexm(objetivo, "(TIROIDE|LEVOTIROXINA|TIRO DUVIDAS|REFACA|FARMACIA|RETIROU|DIALEVOTIROXINA|FARMACOS|TUMEFACAO|FARMACEUTICO|FARMACOLOGICO|ALARMA|TIROU|RETIRO|AFERIDA)")
    The issue I'm having is that the excluded terms are still coming up. For example, the medical record in the variable "objetivo" containing notes (personal/sensitive information redacted): "REFERE QUE FEZ O TESTE DA FARMACIA PARA GRAVIDEZ" was not excluded despite "FARMACIA" being an excluded term in the search. I appreciate the text is in Portuguese, but hope that the inclusion/exclusion question is clear.

    I have not provided a dataex file as this dataset contians identifiable data and I can't guarantee the medical records do not contain personal/sensitive information.

    I am using Stata 18 for reference.

    Happy to provide more information if necessary.

    Appreciate any help, thank you in advance.
    Kind regards

  • #2
    what do you want to achive with subjetivo[-5/5]
    Last edited by Bjarte Aagnes; 02 May 2024, 10:54.

    Comment


    • #3
      Originally posted by Bjarte Aagnes View Post
      what do you want to achive with subjetivo[-5/5]
      Thanks for your response!

      The terms/phrases following subjetivo[-5/5] should be excluded if within 5 terms, before or after, the included terms/phrases.
      i.e. if
      NAMORAD.*|PARCEIR.*|MARIDO|MULHER|ESPOS.* ... are within 5 words of
      TIRO.*|ARMA.*|PISTOL.*|ESFAQUEA.*| ... then the record weap_firearm should = 0 Though admittedly, this is not my main concern. I am primarily trying to understand why the incorrect terms are still being picked up.

      Comment


      • #4
        Well, Your (privat notation) subjetivo[-5/5] will return an empty string which will not be match by the regex.

        Comment


        • #5
          Originally posted by Bjarte Aagnes View Post
          Well, Your (privat notation) subjetivo[-5/5] will return an empty string which will not be match by the regex.
          Sorry could you clarify?

          If I take out subjetivo[-5/5] , should the search work?

          Comment


          • #6
            Better to ask about your actual problem rather than your attempted solution (see the XY problem). FAQ Advice #12 addresses the issue of confidential data.

            If your dataset is confidential, then provide a fake example instead.

            Comment

            Working...
            X