Announcement

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

  • medication use in each quarter

    Dear Stata users,


    I am looking at medication use from the 2 years before and after the event in patients with chronic kidney disease. I would like to divide time before and after event into 3 months quarters, numbering the 8 quarters before the event as -Q8 to -Q1 and after the event as Q1 to Q8 and examine the medication use (14 classes of medications) in each quarter. I would really appreciate If anyone may help me with the analysis.
    Data looks as below.



    PHP Code:
    [CODE]
    Example generated by -dataex-. To installssc install dataex
    clear
    input byte ID str9 atc5 float
    (supply_date event_date)
    "A10AD05" 16672 16672
    "C02AC04" 17484 16672
    "C06AD05" 17402 16672
    "A10AC04" 18215 16672
    "A01AD05" 15576 16672
    "B01AC04" 16023 16672
    "C10AA05" 17484 16672
    "B01AC04" 17698 17020
    "A01AD05" 15506 17020
    "B01AC04" 16237 17020
    "A01AD05" 16602 17020
    end
    format 
    %td supply_date
    format 
    %td event_date
    [/CODE

    Many thanks.
    Sincerely,
    Oyun

  • #2
    Your question is unclear. In your example data, ID 2 has two different event dates, 24aug2005 and 07aug2006. So if ID2 also had an observation with supply date, say 1jan2006, would that be classified as 8 months before 07aug2006, or 4 months after 24aug2005? What's the rule for resolving this kind of overlap?

    Comment


    • #3
      As Clyde mentioned, you will probably need to give a little more context about your data and what you are trying to accomplish. But more generally, when dealing with quarterly data and questions like, "was the patient taking medication x six quarters prior to being diagnosed with chronic kidney disease?" I have found the following Stata commands to be helpful:

      Code:
      gen event_qtr = quarter(event_date) 
      gen event_year = year(event_date)
      egen event_year_qtr = concat(event_year event_qtr), p("-") 
      /* Because this concatenates, 2005-3 is a 7-character string */
      
      clonevar event_date2 = event_date
      format event_date2 %dCY-q  /* Doing it this way just displays "24 AUG 2005" as 2005-3 */
      It also often helpful to create a "Year-qtr.dta" Stata file that just assigns a number to each quarter. For example, 2002-q1 is 1, 2002-q2 is 2, and so on. This makes it a lot easier to count how many unique medicines a patient was taking in the 8 qtrs prior to the current event. (or to sum things across quarters, "How many times did was the patient admitted to a hospital in the prior 8 quarters?", etc.)

      For example, if your event data goes from 2005 to 2010, so +/- 8 quarters would go from 2003 to 2012 (obviously, there is no harm if you instead created it from 2000 to 2020 or whatever. You might want to do that if you are going to be re-using this file). You could do something like this:
      Code:
      insheet using "C:\DATA\year-qtr base.csv" // This spreadsheet or CSV just has the numbers 2003-2002 in a column labeled "year"
      expand 4  /* This makes it so there are 4 copies of everything (i.e. original plus 3 new copies), although it is unsorted  */
      sort year
      
      by year: gen qtr = _n   /* creates 4 qtrs (because 4 obs) per year */
      egen year_qtr = concat(year qtr), p("-")   /* The p("-") means "separate with a dash" */
      label var year_qtr "Year & qtr (2000-3) that event took place; var is a string"
          
      gen year_qtr_number = _n 
      label var year_qtr_number "Unique id for each year_qtr, 2003-1 is 1, 2003-2 is 2"
      Obviously you would need to rename some of the variables so that you could merge them in the way you wanted to. But it makes it easier to work with quarters. If year_qtr_number==1 for q1 of 2003, then 2005-q3 becomes (year_qtr_number==11), and 8 qtrs after that is q3 of 2007 (year_qtr_number==19).

      Hope that helps!
      --David

      Comment


      • #4
        I have a different stance to offer. Without being a medic, I am nevertheless confident that conventional or even unconventional quarter years have no intrinsic physiological or other medical significance. You have daily data: why degrade the time resolution? You can always choose suitable windows defined in terms of days before the present.

        That aside, it seems to me that the function qofd() offers a direct mapping from daily dates to quarterly dates. I can't follow David's alternative which starts by identifying years and quarters separately and then putting them together again.

        Comment


        • #5
          This is why Stata (& statalist) is so cool! Stata already has a function qofd(event_date) that does what I was trying to create manually with my code above.

          Comment


          • #6
            Thank you so much for your help David and Nick. I will try the codes.


            Sorry for unclear for Clyde. I've generated -dataex again as suggested.

            PHP Code:
            [CODE]
            Example generated by -dataex-. To installssc install dataex
            clear
            input byte ID str9 atc5 float
            (supply_date event_date)
            "A10AD05" 15627 16303
            "C02AC04" 15644 16303
            "C06AD05" 15753 16303
            "A10AC04" 17790 16303
            "A01AD05" 17790 16303
            "B01AC04" 17839 16303
            "C10AA05" 15522 17494
            "B01AC04" 15529 17494
            "A01AD05" 15711 17494
            "B01AC04" 17821 17494
            "A01AD05" 18157 17494
            end
            format 
            %td supply_date
            format 
            %td event_date
            [/CODE

            Sincerely,
            Oyun

            Comment


            • #7
              Code:
              clear
              input byte ID str9 atc5 float(supply_date event_date)
              1 "A10AD05" 15627 16303
              1 "C02AC04" 15644 16303
              1 "C06AD05" 15753 16303
              1 "A10AC04" 17790 16303
              1 "A01AD05" 17790 16303
              1 "B01AC04" 17839 16303
              2 "C10AA05" 15522 17494
              2 "B01AC04" 15529 17494
              2 "A01AD05" 15711 17494
              2 "B01AC04" 17821 17494
              2 "A01AD05" 18157 17494
              end
              format %td supply_date
              format %td event_date
              
              //    VERIFY ONLY ONE EVENT-DATE PER ID
              by ID (event_date), sort: assert event_date[1] == event_date[_N]
              
              gen quarter = qofd(supply_date)
              gen event_quarter = qofd(event_date)
              format *quarter %tq
              
              gen quarter_diff = quarter - event_quarter

              Comment


              • #8
                Thank you so much for your help prof.Schechter.

                Comment

                Working...
                X