Announcement

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

  • Issues with getting minimum date value in a data set

    Hi there I'm having issues trying to identify the minimum value of date of dispensation for each drug in the data set. Here's a sample data set and I've also attached a PDF copy to make it easier to read.

    Rcpt_Anon_ID str8 DRUG_DIN double DSPN_AMT_QTY long DSPN_DATE double DSPN_DAY_SUPPLY_QTY str10 Prscb_Anon_ID str8 SUPP_DRUG_ATC_CODE
    "000009106" "02261731" 3 18169 84 "390203576" "G03AA12"
    "000009106" "02405628" 90 19971 90 "531829076" "C10AA07"
    "000009106" "02353377" 180 19031 90 "277246846" "A10BA02"
    "000009106" "02282445" 30 19400 30 "277246846" "N05CF01"
    "000009106" "02405628" 90 20765 90 "277246846" "C10AA07"
    "000009106" "02353377" 180 19838 90 "130332376" "A10BA02"
    "000009106" "02405628" 90 21186 90 "385893456" "C10AA07"
    "000009106" "02282445" 90 20974 90 "277246846" "N05CF01"
    "000009106" "02353377" 180 19115 90 "277246846" "A10BA02"
    .
    Here's the code I ran to try and get a minimum date value for this data set

    g opioid=substr(SUPP_DRUG_ATC_CODE,1,4)=="N02A"

    . by Rcpt_Anon_ID: egen o_date = min(opioid) if opioid ==1

    . format o_date %tdD_m_Y

    . display o_date

    after running the date, I'm not getting any values in return.

    Any help would be great, thank you
    Attached Files

  • #2
    Your question is unclear. Do you need the earliest dispensation date of each drug across all patients, or, for each patient, do you want the earliest dispensation date of each drug the patient gets? I'm going to assume it's the latter.

    Code:
    clear*
    input str12 Rcpt_Anon_ID str8 DRUG_DIN double DSPN_AMT_QTY long DSPN_DATE double DSPN_DAY_SUPPLY_QTY str10 Prscb_Anon_ID str8 SUPP_DRUG_ATC_CODE
    "000009106" "02261731" 3 18169 84 "390203576" "G03AA12"
    "000009106" "02405628" 90 19971 90 "531829076" "C10AA07"
    "000009106" "02353377" 180 19031 90 "277246846" "A10BA02"
    "000009106" "02282445" 30 19400 30 "277246846" "N05CF01"
    "000009106" "02405628" 90 20765 90 "277246846" "C10AA07"
    "000009106" "02353377" 180 19838 90 "130332376" "A10BA02"
    "000009106" "02405628" 90 21186 90 "385893456" "C10AA07"
    "000009106" "02282445" 90 20974 90 "277246846" "N05CF01"
    "000009106" "02353377" 180 19115 90 "277246846" "A10BA02"
    end
    format DSPN_DATE %td
    
    by DRUG_DIN Rcpt_Anon_ID, sort: egen earliest_dispensation = min(DSPN_DATE)
    format earliest_dispensation %td
    I don't understand the point of the code you show, so I'm not going to try to troubleshoot it.

    It appears that you started to use -dataex- to show your example data, but then you edited it in some strange way that made it unusable. Please be sure to use -dataex- when you show example data, and when you do so, be sure to show the entire -dataex- output from the start to the end, without edits.

    Comment


    • #3
      Clyde Schechter gave excellent advice. The intent of #1 may have been

      Code:
      by Rcpt_Anon_ID: egen o_date = min(cond(substr(SUPP_DRUG_ATC_CODE,1,4)=="N02A", DSPN_DATE, .))
      No dates come out of the code in #1, because none are ever touched.

      Comment

      Working...
      X