Announcement

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

  • Polypharmacy algorithm

    Hello All,
    I am trying to create algorithms to count Polypharmacy following the article:https://www.longdom.org/open-access/...52.1000151.pdf
    from Electronic Health Data that looks like:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte id float fill_date str12 Drug byte Duration
    1 21652 "Metformin" 30
    1 21652 "Simvastatin" 30
    1 21652 "Aspirin" 30
    1 21652 "Amaryl" 60
    1 21710 "Metformin" 30
    1 21710 "Simvastatin" 30
    1 21710 "Aspirin" 60
    1 21740 "Metformin" 30
    1 21740 "Amaryl" 30
    1 21740 "Aspirin" 30
    1 21771 "Metformin" 30
    1 21771 "Amaryl" 30
    1 21771 "Aspirin" 30
    1 20708 "Metformin" 30
    1 20708 "Amaryl" 30
    1 21803 "Aspirin" 30
    1 21803 "Simavastatin" 30
    end
    format %tdDD/NN/CCYY fill_date

    First: I want to see for different patients if >= 5 drugs were used for >= 60 days in a year.
    Second: I want to see for different patients if >= 5 drugs were used for >= 60 days per quarter.
    Thank you in advance for help!

  • #2
    Thank you for using -dataex- on your very first post, and for providing a link to a relevant paper.

    Please clarify. The paper you linked shows 3 different algorithms. Which one are you trying to follow? In another respect, it appears to be none of them since the article does not use >= 5 drugs as a cutoff.

    Comment


    • #3
      Thank you Clyde for your reply. I am trying to follow The first and second one. Unfortunately, there is no consensus on defining polypharmacy. However, previous studies (including the attached paper) is defining it as using five or more medications simultaneously.

      Comment


      • #4
        I think what you need is this:

        Code:
        gen end_date = fill_date + Duration
        format %tdDD/NN/CCYY fill_date
        
        gen long obs_no = _n
        reshape long @date, i(obs_no) j(_event) string
        gen int event = cond(_event == "fill_", 1, -1)
        by id (date event), sort: gen drugs_in_use = sum(event)
        gen year = yofd(date)
        gen quarter = qofd(date)
        format quarter %tq
        
        by id year, sort: egen polypharmacy_year = max(drugs_in_use >= 5)
        by id quarter, sort: egen polypharmacy_quarter = max(drugs_in_use >= 5)

        Comment


        • #5
          Thank you Clyde for this very helpful Code. I think I confused you when I defined Polypharmacy.
          The first algorithm in the paper calculated Polypharmacy as using >= 5 medications for 60 days in a given year.
          The second algorithm in the paper calculated Polypharmacy as using >= 5 medications for 60 days in a quarter.

          Comment


          • #6
            Oh, I just realized I implemented a different criterion. The code I wrote will just show you whether there were, at any point in time, 5 or more medications in simultaneous use, during a quarter or year. But that could be only for a few days, or even just one day. The following code identifies spells of 60 or more days where 5 drugs are simultaneously in use:

            Code:
            gen end_date = fill_date + Duration
            format %tdDD/NN/CCYY fill_date
            
            gen long obs_no = _n
            reshape long @date, i(obs_no) j(_event) string
            gen int event = cond(_event == "fill_", 1, -1)
            by id (date event), sort: gen drugs_in_use = sum(event)
            gen year = yofd(date)
            gen quarter = qofd(date)
            format quarter %tq
            
            //    IDENTIFY PERIODS WITH >= 5 DRUGS IN USE THAT SPAN AT LEAST 60 DAYS
            gen byte five_or_more = (drugs_in_use >= 5)
            by id (date event): gen spell = sum(five_or_more != five_or_more[_n-1])
            by id spell (date event): gen duration = date[_N] - date[1]
            by id spell (date event): gen polypharmacy = (duration >= 60 & five_or_more)
            
            by id year, sort: egen polypharmacy_year = max(polypharmacy)
            by id quarter, sort: egen polypharmacy_quarter = max(polypharmacy)
            Now, note that any particular 60 day spell of 5-drug (or more) use might overlap two quarters, or even two years. The code above will count such a spell in both of the overlapped years/quarters. That is, if a patient is using five drugs from March 1, 2019 through April 30, 2019, that will be marked as polypharmacy in both 2019Q1 and 2019Q2.

            Comment


            • #7
              Hello Clyde,
              Thanks again for your response. Now, your code successfuly counted five medications or more and identified Polypharmacy correctly. However, I think there is a problem with duration you created and I cannot identify it. For example in the following data:
              * Example generated by -dataex-. To install: ssc install dataex
              clear
              input byte id float fill_date str12 Drug byte Duration
              2 21561 "Metformin" 60
              2 21561 "Simvastatin" 60
              2 21561 "Aspirin" 60
              2 21608 "Amlodipine" 60
              2 21608 "Bisprolol" 60
              2 21651 "Metformin" 60
              2 21651 "Simvastatin" 60
              2 21651 "Aspirin" 60
              end
              format %tdDD/NN/CCYY fill_date

              I am sure that this patient used 5 medications simultaneously for at least 10 days but the duration came 0.

              Comment


              • #8
                You are correct, my code for the duration was wrong because sometimes the spell contained only one observation and was counted as 0 duration even though it should have run until the next event. That is corrected in the following code. Note, by the way, that it is not possible to determine the duration of some spells. For example, in your data, as of 10 June 2019, your patient has no drugs in use, as all of his previous prescriptions have expired. But we have no way to know whether he was issued new prescriptions immediately thereafter, or at a remote time, or perhaps never. So the duration of this spell of fewer than 5 medications is indeterminate.

                Code:
                gen end_date = fill_date + Duration
                format %tdDD/NN/CCYY fill_date
                
                gen long obs_no = _n
                reshape long @date, i(obs_no) j(_event) string
                gen int event = cond(_event == "fill_", 1, -1)
                by id (date event), sort: gen drugs_in_use = sum(event)
                gen year = yofd(date)
                gen quarter = qofd(date)
                format quarter %tq
                
                //    IDENTIFY PERIODS WITH >= 5 DRUGS IN USE THAT SPAN AT LEAST 60 DAYS
                gen byte five_or_more = (drugs_in_use >= 5)
                by id (date event): gen spell = sum(five_or_more != five_or_more[_n-1])
                by id (date event): gen through = date[_n+1]-1
                by id spell (date event), sort: gen duration = through[_N] - date[1] + 1
                by id spell (date event): gen polypharmacy = (duration >= 60 & five_or_more)
                replace polypharmacy = . if polypharmacy == 1 & missing(duration)
                
                by id year, sort: egen polypharmacy_year = max(polypharmacy)
                by id quarter, sort: egen polypharmacy_quarter = max(polypharmacy)

                Comment


                • #9
                  Thank you so much! This works perfectly.

                  Comment

                  Working...
                  X