Announcement

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

  • generating variable if word "x" in string variable

    Hi all,

    I have a string variable with a lot of different categories. I would like to generate some dummy variables, that, for example, =1 if the word "assault" is in the string variable. Some example data below. Thanks for help in advance. -CJ

    Code:
    clear
    input str100 max_charge
    "(182701A1) -  Simple Assault"                                                       
    "(182701A1) -  Simple Assault"                                                       
    "(182701A1) -  Simple Assault"                                                       
    "(182701A1) -  Simple Assault"                                                       
    "(182701A1) -  Simple Assault"                                                       
    "(182702A2) -  Aggravated Assault"                                                   
    "(182702A2) -  Aggravated Assault"

  • #2
    here is one (of many) way:
    Code:
    gen byte wanted=strpos(max_charge,"Assault")>0 | strpos(max_charge,"assault")>0

    Comment

    Working...
    X