Announcement

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

  • Reformating hour variable

    Hello!
    My dataset includes exams information:
    1. starttime - the hour the exam started
    2. duration_hours - the exam duration in hours.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str5 starttime double duration_hours
    " 9:00" -1.8934488e+12
    " 9:00" -1.8934452e+12
    " 9:00" -1.8934452e+12
    " 9:00" -1.8934452e+12
    " 9:00" -1.8934488e+12
    " 9:00" -1.8934488e+12
    " 9:00" -1.8934452e+12
    " 9:00" -1.8934488e+12
    " 9:00" -1.8934488e+12
    end
    format %tcHH:MM:SS duration_hours
    I would like to convert the format of these two variables.
    It should look like this for starttime:
    Orginial starttime New starttime
    9:00 900
    10:30 1030
    14:30 1430
    and for duration_hours:
    Original duration_hours New duration_hours
    15:30 1530
    18:00 1800
    I want to use this variables for calculations so I need them in int storage type.

    Thanks in advance!

  • #2
    For calculation, you should not want integers 1530 and 1800 as the difference between them is 270 (minutes) not 150.

    How did . -1.8934488e+12 namely


    Code:
    . di %tc -1.8934488e+12
    31dec1899 02:00:00
    ever get into your data? At a wild guess something has been imported from other software with a time origin at some point in 1900.

    Comment


    • #3
      Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

      All Stata manuals are included as PDFs in the Stata installation and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

      Comment

      Working...
      X