Announcement

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

  • How to filter data using keywords

    Hi everyone,

    I am a novice user of STATA. I have collected execucomp data on excel, where manager data is available according to their titles and company name. Out of all the managers listed, I only want to work with the CEOs, so only the datapoints with the the titles "CEO" or "executive" or "Chief Executive Officer" would suffice for me. Can anyone help me out with the appropriate codes to filter out data with keywords?

    Thanks a lot!

    Wali

  • #2
    Code:
    keep if strpos(title, "CEO") | strpos(title, "executive") | strpos(title, "Chief Executive Officer")

    Comment


    • #3
      Clyde Schechter is there an advantage of using

      Code:
      keep if strpos(title, "CEO")
      to
      Code:
      keep if regexm(title, "CEO")
      or is it a matter of preference?

      Comment


      • #4
        I think it's a matter of preference. My preference for -strpos()- arises just because I find regular expressions pretty complicated to write, so I tend to avoid them when there is a reasonable alternative.

        Also, if this command is being applied to a very large data set and is also deep inside a loop with a very large number of iterations, I imagine that -strpos()- executes faster than -regexm()-, and the difference could be noticeable.

        Comment


        • #5
          Thanks! They were very helpful!

          Comment

          Working...
          X