Announcement

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

  • Generate if Variable which is 1, if x y 0r z is 1

    I want to generate "shock", which should be 1, if (h16q01101 | h16q01102 | h16q01103 | h16q01104 | h16q01105 | h16q01106 | h16q01107 | h16q01108 | h16q01109 | h16q01110 | h16q01111 | h16q01112 | h16q01113 | h16q01114 | h16q01115 | h16q01116 | h16q01117 | h16q01118) is 1
    can anyone help me?
    Anda yes I have already ask to change my name!
    generate shock = .
    replace shock = 1 if inlist(h16q01101 | h16q01102 | h16q01103 | h16q01104 | h16q01105 | h16q01106 | h16q01107 | h16q01108 | h16q01109 | h16q01110 | h16q01111 | h16q01112 | h16q01113 | h16q01114 | h16q01115 | h16q01116 | h16q01117 | h16q01118)

  • #2
    Take a look at the help for -egen-, particularly the anymatch() function. If your variables h16q01101 through h16q0118 are located consecutively in your data set it is as simple as

    Code:
    egen shock = anymatch(h16q01101-h16q01118), values(1)
    If they are not consecutively located, you might want to rearrange the data set (-order- command) to bring that about. By the way if these 18 variables are the only variables whose names begin with h16q01, then you can simplify the function call further by just specifying h16q11*, and that doesn't depend on their location in the data.

    Comment


    • #3
      A review of technique in this territory is available at ​http://www.stata-journal.com/article...article=pr0046

      Comment

      Working...
      X