Announcement

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

  • Working with Range of Dates

    I have a dataset which includes Unique ID number, Date of Admission and Date of Order of antibiotics. The data has multiple entries for date of admission and date of order of antibiotics. The question I want to answer is whether the patient was on antibiotics on or before 30 days of admission.

    Example Dataset.
    ID Number Admission Date Date of Order
    1
    12/30/2015
    12/11/2015
    1
    12/30/2015
    12/30/2015
    2 4/18/2015 1/22/2015
    2 12/28/2015 4/20/2015
    2 1/20/2015 4/21/2015
    2 5/20/2015 7/16/2015
    2 2/25/2016 12/28/2015
    3 2/27/2015 2/23/2015
    4 4/16/2015 4/17/2015
    For each unique ID the challenge is to compare the range of date of order values and see whether it is same or within 30 days prior to the admission date.

  • #2
    Welcome to Statalist.

    You have been slow to get any advice because you did not help the reader by presenting your sample data in a form easily usable in Stata.

    Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question.

    Please be sure to use the dataex command to show your example data. If you are running version 15.1 or a fully updated version 14.2, it is already part of your official Stata installation. If not, run ssc install dataex to get it. Either way, run help dataex to read the simple instructions for using it. dataex will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use dataex.

    The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

    With that said, here is some sample code that counts the orders within 30 days prior to each admission date. It uses the rangestat command, written by Robert Picard and available from SSC - you must first install it by running
    Code:
    ssc install rangestat
    When that is done, here is your data, presented using dataex, and the code that uses it.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte id float(admdate orddate)
    1 20452 20433
    1 20452 20452
    2 20196 20110
    2 20450 20198
    2 20108 20199
    2 20228 20285
    2 20509 20450
    3 20146 20142
    4 20194 20195
    end
    format %td admdate
    format %td orddate
    
    sort id admdate
    generate low = admdate-30
    generate high = admdate
    rangestat (count) N=orddate, interval(orddate low high) by(id)
    list, noobs sepby(id)
    Code:
    . list, noobs sepby(id)
    
      +------------------------------------------------+
      | id     admdate     orddate     low    high   N |
      |------------------------------------------------|
      |  1   30dec2015   11dec2015   20422   20452   2 |
      |  1   30dec2015   30dec2015   20422   20452   2 |
      |------------------------------------------------|
      |  2   20jan2015   21apr2015   20078   20108   . |
      |  2   18apr2015   22jan2015   20166   20196   . |
      |  2   20may2015   16jul2015   20198   20228   2 |
      |  2   28dec2015   20apr2015   20420   20450   1 |
      |  2   25feb2016   28dec2015   20479   20509   . |
      |------------------------------------------------|
      |  3   27feb2015   23feb2015   20116   20146   1 |
      |------------------------------------------------|
      |  4   16apr2015   17apr2015   20164   20194   . |
      +------------------------------------------------+
    Last edited by William Lisowski; 21 Jun 2018, 06:08.

    Comment

    Working...
    X