Announcement

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

  • String management, extract words from a string with different length

    Good morning,
    I have a string variable which different lengths and words inside. My goal is to generate different dummy variables if inside the string some words arise:
    Like:

    Code:
    gen wellness_table = 1 if wellness --contains-- "table"
    which is the right syntax for asking something like that??

    Thank you in advance for your time, wishing you all a pleasant week
    Last edited by Chiara Tasselli; 11 Apr 2022, 03:30.

  • #2
    Code:
    gen wellness_table = 1 if strmatch(wellness,"*table*")

    Comment


    • #3
      Code:
      help strpos
      help regexm
      Code:
      gen wanted1= regexm(lower(wellness), "table")
      gen wanted2= strpos(lower(wellness), "table")>0
      Note that these will pick words such as "comfortable" and "interactable" which include the string "table" within them. If you strictly want the word table, see https://www.statalist.org/forums/for...g-observations

      Comment


      • #4
        Thank you both for your useful advice: you solve my problem.
        Wishing you a peaceful week ahead!

        Comment

        Working...
        X