Announcement

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

  • Displaying time duration greater than 24 hours

    Hi all,

    I'm working on a data set of total working hours per day (mon_total to sat_total) as follows,

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(mon_total tue_total wed_total thu_total fri_total sat_total)
    -1.8934371e+12 -1.8934371e+12 -1.8934371e+12 -1.8934371e+12 -1.8934398e+12 -1.8934371e+12
     -1.893438e+12  -1.893438e+12  -1.893438e+12  -1.893438e+12 -1.8934452e+12  -1.893438e+12
     -1.893438e+12  -1.893438e+12  -1.893438e+12  -1.893438e+12 -1.8934452e+12  -1.893438e+12
    -1.8934371e+12 -1.8934371e+12 -1.8934371e+12 -1.8934371e+12 -1.8934371e+12 -1.8934371e+12
    -1.8934407e+12 -1.8934407e+12 -1.8934407e+12 -1.8934407e+12 -1.8934446e+12 -1.8934446e+12
    -1.8934416e+12 -1.8934416e+12 -1.8934416e+12 -1.8934416e+12 -1.8934461e+12 -1.8934416e+12
    -1.8934389e+12 -1.8934389e+12 -1.8934389e+12 -1.8934389e+12 -1.8934452e+12 -1.8934434e+12
    -1.8934395e+12 -1.8934395e+12 -1.8934395e+12 -1.8934395e+12 -1.8934452e+12 -1.8934434e+12
    -1.8934389e+12 -1.8934389e+12 -1.8934389e+12 -1.8934389e+12 -1.8934452e+12 -1.8934389e+12
    end
    format %tchh:MM mon_total
    format %tchh:MM tue_total
    format %tchh:MM wed_total
    format %tchh:MM thu_total
    format %tchh:MM fri_total
    format %tchh:MM sat_total
    I would like to make a summation of mon_total until sat_total to find out the total working hour per week using egen rowtotal. However, whenever there's a summation result exceeding 24 hours (for example 25 hours and 45 minutes) stata displays it as 1:45. Is there a way to display a time duration which exceeds 24 hours as it is? Many thanks in advance!

  • #2
    So, the information you have in your dataset is not "total working hours", but actually the number of milliseconds since 01jan1960 00:00:00.000. You can see this if you change the display format of one of your variables:

    Code:
    format sat_total %tcMonth_dd,_CCYY_hh:MM_am
    . list sat_total, noobs
    
      +---------------------------+
      |                 sat_total |
      |---------------------------|
      | December 31, 1899 5:15 am |
      | December 31, 1899 5:00 am |
      | December 31, 1899 5:00 am |
      | December 31, 1899 5:15 am |
      | December 31, 1899 3:10 am |
      |---------------------------|
      | December 31, 1899 4:00 am |
      | December 31, 1899 3:30 am |
      | December 31, 1899 3:30 am |
      | December 31, 1899 4:45 am |
      +---------------------------+
    I don't think this is a particularly useful setup for addition. Instead, you want the number of hours & minute for each day so you can add them. Here's one way:

    Code:
    gen mon_hrs=hhC(mon_total)+(mmC(mon_total)/60)
    This gives you the number of hours (and fraction of hours) worked on Monday. Alternatively, you could calculate the total number of minutes worked per day:
    Code:
    gen mon_mins=(hhC(mon_total)*60)+ mmC(mon_total)
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Hi Carole!

      Thanks for the help, it worked! I didn't realize the format was cumbersome as I imported it from excel with the [h]:mm:ss format. Thanks again!

      Comment

      Working...
      X