Announcement

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

  • Querying multiple variables at a time

    Hi everyone,
    I am working in a database where each patient has fifteen procedure variables: proc1 proc2 proc3 ... proc14 proc15
    I would like to generate a new variable, "int", if any variable from proc1-proc15 == "intubation".
    Is there a more efficient way to achieve this than:

    generate int = 0
    replace int = 1 if proc1=="intubation"|proc2=="intubation"|proc3=="in tubation"|proc4=="intubation"|proc5=="intubation"| etc etc etc

    Thank you in advance!

  • #2
    Here are two ways to do it.

    Code:
    #1 
    generate int = 0
    
    forval j = 1/15 { 
        replace int = 1 if proc`j' == "intubation"
    } 
    
    
    #2 
    gen int = inlist("intubation", proc1, proc2, proc3, proc4, proc5, proc6, proc7, proc8) 
    replace int = int | inlist("intubation", proc9, proc10, proc11, proc12, proc13, proc14, proc15)
    See

    Code:
    help inlist()
    on the limits there, ,

    Comment


    • #3
      Thank you Nick!

      Comment

      Working...
      X