Announcement

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

  • Calculating day-level statistics with data that may span across several days

    Hi,

    Data at hand: patient visit start and end dates/times, with each line representing a unique visit. A sample is below. The visits span from several hours to several days.

    Question we're looking to answer: for each day, what proportion of patients who were there in the morning (0800) had left by the end of the day (2359).

    The only set of steps that I can sketch in my brain (though not yet sure how to code it) would be to create two variables for each day to create flags to identify whether each observation was present at 0800 then if they had left by 2359, then somehow calculate proportions for each of these variables. Is there an easier way?

    Thanks!

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id obsbegin obsend)
     1 1.8619213e+12  1.861961e+12
     2  1.861922e+12 1.8620786e+12
     3  1.861923e+12 1.8619218e+12
     4 1.8619246e+12  1.861973e+12
     5  1.861929e+12  1.861966e+12
     6 1.8619295e+12 1.8619564e+12
     7 1.8619327e+12 1.8620413e+12
     8 1.8619335e+12 1.8619677e+12
     9  1.861934e+12 1.8619636e+12
    10 1.8619395e+12 1.8619865e+12
    11 1.8619415e+12 1.8619577e+12
    12 1.8619433e+12 1.8619715e+12
    13  1.861949e+12  1.861985e+12
    14  1.861961e+12 1.8620724e+12
    15  1.861965e+12 1.8619995e+12
    16 1.8619742e+12 1.8619744e+12
    17  1.861979e+12 1.8620514e+12
    18  1.861987e+12  1.862078e+12
    19 1.8619886e+12 1.8620075e+12
    20  1.861995e+12  1.862071e+12
    21 1.8619962e+12  1.862055e+12
    22 1.8620012e+12  1.862016e+12
    23 1.8620025e+12 1.8620584e+12
    24  1.862021e+12 1.8620544e+12
    25 1.8620255e+12 1.8620362e+12
    end
    format %tc obsbegin
    format %tc obsend
    Last edited by Will Fleischman; 21 Feb 2019, 14:40.

  • #2
    Pinging the thread to see if anyone has any suggestions. Also, please let me know if my question/data above is not clear and how I can improve it. Thanks much.

    Comment


    • #3
      I think your basic strategy is what I would do also; here is one set of steps (could be done in fewer but would be much harder for me to read):
      Code:
      gen date1=dofc(obsbegin)
      format date1 %td
      gen date2=dofc(obsend)
      format date2 %td
      gen timein=hh(obsbegin)
      gen byte wanted=date2==date1 & timein<8
      this gives you a 0/1 variable that is 1 if your conditions are me- you can tabulate or do anything else you want (e.g., summarize to get proportions)

      Comment

      Working...
      X