Announcement

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

  • Using "strpos" to create new variable

    I want to use the command "strpos" to extract specific observations from a string variable. Im using the command below,
    "g newvar = 1 if strpos(var1, "[1]")>0 "

    The using variable "var1" looks like below

    var1

    0 1 2 3
    3 4 0 1


    I would like to create a variable that takes the value 1 if var1 consists string obs 1. ​​​​​​​Any help on this would be really appreciated.

  • #2
    Code:
    g newvar =  strpos(var1, "1") > 0

    Comment


    • #3
      Thank you, this was very helpful.

      Comment

      Working...
      X