Announcement

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

  • Replace if multiple values of a variable

    Hello,

    I would like to replace a variable if values of a different variable are one of a set of values

    For example, replace var1=1 if var2 is 746, 743, 987, 123, etc. The list is pretty long, so I would like to avoid typing out replace var1=1 if var2==743 | var2==746....etc.

    Thanks,
    Alyssa

  • #2
    Code:
    replace var1 = 1 if inlist(var2, 746, 743, 987, 123)
    is one kind of shortening.

    Otherwise, consider the merge technique in https://www.stata.com/support/faqs/d...s-for-subsets/

    Comment

    Working...
    X