Announcement

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

  • How can I select observations containing specific words?

    Dear all,

    I need to pick persons A & B whose position include exact "Independent" from the list as follow

    Directors Position
    A Non-executive Independent Director
    B Independent Non-executive Director
    C Non-executive Director
    D Non-executive Chairman of Board
    E Non-Independent Non-executive Director

    How can I do that? Because if I use the command

    Code:
    gen InD=regexm(CurrentPosition,"Independent")
    Person E is chosen too.

    Thank you

  • #2

    Code:
    gen wanted = strpos(lower(CurrentPosition), "independent") > 0  & strpos(lower(CurrentPosition), "non-independent") == 0
    That code corrects for variations in case but not otherwise for misspellings or abbreviations.

    Comment


    • #3
      This is an alternative including "Non-independent":

      Code:
      gen myvar = regexm(var1, "[Ii]ndependent")
      Edited: sorry, this would unfortunately preserve the "Non-Independent" term.
      Last edited by Marcos Almeida; 31 Mar 2019, 07:48.
      Best regards,

      Marcos

      Comment


      • #4
        Heureka.

        This command may cope with initials (lower or upper) as well:

        Code:
        gen myvar2 = regexm(var1, "[Ii]ndependent") & strpos(var1, "Non-Independent") ==0
        Best regards,

        Marcos

        Comment


        • #5
          Thank you very much for your help !

          Comment

          Working...
          X