Announcement

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

  • #16
    Code:
     
     gen switch_within = . local amlodipinecombo c09dx03 c09dx01 c09db04 c09db02 c09db01 c10bx03 c08ca01 c09bb04 forvalue i = 1/8 {     local first_code = word("`amlodipinecombo'", `i')     forv j = 1/8{         local second_code = word("`amlodipinecombo'", `j')         if `i' != `j' {             di "`first_code' with `second_code'"             forv k = 1(1)5 {                 bysort pat_id: replace switch_within = 1 if (dispensed_q2 == 1 & dispensed_q2[_n-`k'] == 1) | (dispensed_q2 == 1 & dispensed_q2[_n+`k'] == 1) & ((ATCcode == "`first_code'" & ATCcode[_n-`k'] == "`second_code'") | (ATCcode == "`first_code'" & ATCcode[_n+`k'] == "`second_code'"))              }         }     } }

    Comment


    • #17
      Okay, I see it now. So actually all of these are false positives, because they all contain transitions with ATCcodes that aren't in the amlodipinecombo list, correct?

      I think you have an order of operations problem. You have something like A or B and C, which Stata interprets as A or (B and C), but you actually want (A or B) and C. I think you need to wrap the first logical 'or' in parentheses like this:

      Code:
      gen switch_within = .
      local amlodipinecombo c09dx03 c09dx01 c09db04 c09db02 c09db01 c10bx03 c08ca01 c09bb04
      forvalue i = 1/8 {
          local first_code = word("`amlodipinecombo'", `i')
          forv j = 1/8{
              local second_code = word("`amlodipinecombo'", `j')
              if `i' != `j' {
                  di "`first_code' with `second_code'"
                  forv k = 1(1)5 {
                      bysort pat_id: replace switch_within = 1 if ((dispensed_q2 == 1 & dispensed_q2[_n-`k'] == 1) | (dispensed_q2 == 1 & dispensed_q2[_n+`k'] == 1)) & ((ATCcode == "`first_code'" & ATCcode[_n-`k'] == "`second_code'") | (ATCcode == "`first_code'" & ATCcode[_n+`k'] == "`second_code'"))
                   }
              }
          }
      }

      Comment


      • #18
        That's correct, I'll look into it
        Last edited by Tabitha Green; 01 Aug 2023, 00:38.

        Comment


        • #19
          Okay, so the good news is, I think this code is capturing all the switches within for amlodipine combinations but I'm still getting some false positives. I've done a bit of an investigation to work out the pattern and the loop seems to be miscoding when a participant has more than two medicines dispensed in Q2. Here is an example (below), it has captured the amlodipine dispensed in Q2 but without it having an alternative combination product in Q2. Rather, it appears the atorvastatin and/or amoxicillin has been considered in the loop but they haven't matched with the local macros so they haven't been coded with a 1.

          Code:
          pat_id    ATCcode    drug_name    dispensed_q2    dispensed_q4    switch_within
          5379    c08ca01    amlodipine        1    
          5379    c09bb04    perindopril + amlodipine    1        1
          5379    c10aa05    atorvastatin    1    1    
          5379    j01ca04    amoxicillin    1
          Am I making any sense? Any ideas?

          Comment


          • #20
            Okay, so here I think the problem is that the dispensed_q2 logic is independent of the ATCode logic. I think this is the fix:

            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input float pat_id str7 ATCcode strL drug_name float(dispensed_q2 dispensed_q4 switch_within)
            ...
            5379 "c08ca01" "amlodipine"                                 . 1 .
            5379 "c09bb04" "perindopril + amlodipine"                   1 . 1
            5379 "c10aa05" "atorvastatin"                               1 1 .
            5379 "j01ca04" "amoxicillin"                                1 . .
            end
            
            drop switch_within
            gen switch_within = .
            local amlodipinecombo c09dx03 c09dx01 c09db04 c09db02 c09db01 c10bx03 c08ca01 c09bb04
            forvalue i = 1/8 {
                local first_code = word("`amlodipinecombo'", `i')
                forv j = 1/8{
                    local second_code = word("`amlodipinecombo'", `j')
                    if `i' != `j' {
                        di "`first_code' with `second_code'"
                        forv k = 1(1)5 {
                            bysort pat_id: replace switch_within = 1 if (dispensed_q2 == 1 & dispensed_q2[_n-`k'] == 1 & ATCcode == "`first_code'" & ATCcode[_n-`k'] == "`second_code'") | (dispensed_q2 == 1 & dispensed_q2[_n+`k'] == 1 & ATCcode == "`first_code'" & ATCcode[_n+`k'] == "`second_code'")
                         }
                    }
                }
            }

            Comment


            • #21
              That's the one! That works perfectly for amlodipine combinations and I've tested it again with other combination medicines in my random sample and it's looking good! Thank you so much!

              Comment


              • #22
                You're welcome, happy to help!

                Comment

                Working...
                X