Announcement

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

  • Data cleaning questions

    Hello Colleagues, I would like to ask about whether there would be a fast way to do the data cleaning as showing below.
    My purpose is that if one of the antibiotics indication used "imipenem", the output of imipenem will be "1. Yes".
    Because I have almost of 200 antibiotics for data cleaning. I would be very time consumption.
    I would be grateful if the colleagues would be able to give me some guidance for this situation.
    Thank you.


    *Experiences of antibiotics
    gen imipenem = 0
    replace imipenem = 1 if antibiotic_1 == " imipenem " | ///
    antibiotic_2 == " imipenem " | ///
    antibiotic_3 == " imipenem " | ///
    antibiotic_4 == " imipenem " | ///
    antibiotic_5 == " imipenem " | ///
    antibiotic_6 == " imipenem " | ///
    antibiotic_7 == " imipenem " | ///
    antibiotic_8 == " imipenem " | ///
    antibiotic_9 == " imipenem " | ///
    antibiotic_10 == " imipenem " | ///
    antibiotic_11 == " imipenem " | ///
    antibiotic_12 == " imipenem " | ///
    antibiotic_13 == " imipenem " | ///
    antibiotic_14 == " imipenem " | ///
    antibiotic_15 == " imipenem " | ///
    antibiotic_16 == " imipenem " | ///
    antibiotic_17 == " imipenem " | ///
    antibiotic_18 == " imipenem " | ///
    antibiotic_19 == " imipenem " | ///
    antibiotic_20 == " imipenem "

  • #2
    Code:
    ds antibiotic_*
    local list = subinstr("`r(varlist)'"," ",`"+"|"+"',.)
    gen imipenem = ustrregexm("imipenem",`list')

    Comment


    • #3
      That is a cute solution, but this may appeal on other grounds: Change 20 as needed.

      Code:
      gen imipenem = 0
      
      forval j = 1/20 { 
          replace imipenem = 1 if trim(antibiotic_`j') == "imipenem" 
      }

      Comment


      • #4
        Thanks Nick Cox, it is very cool solution.

        Comment

        Working...
        X