Announcement

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

  • Programming "if cell starts with a certain word or phrase"

    Hi,

    I am trying to program in Stata 14.2 so that if a cell (string variable) starts with a certain word or phrase, it should be marked as 1

    I've tried the following:
    generate STUFF=0
    replace STUFF=1 if strpos(stringvariable, "stuff")

    However, this just marks it as 1 if stuff is contained in the string; fx if it says "nice stuff", whereas I need it to only be 1 if it says "stuff that is nice", e.g. the phrase STARTS with stuff.

    Is this possible in Stata?
    I hope the questions makes sense

    Thanks, all the best,
    Line







  • #2
    Look for substr().

    Best
    Daniel

    Comment


    • #3
      Code:
       if strpos(stringvariable, "stuff") == 1 
      is a sufficient twist.

      Comment


      • #4
        How do I overlook these things? Nice(er) solution.

        Comment


        • #5
          Amazing - thank you so much!!

          Comment

          Working...
          X