Announcement

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

  • Converting numeric values into time

    Hello!

    In my dataset, I have a column "time_out" which has numeric values such as 17.45 or 18.36 etc. These values basically indicate that the person went out at 5:45 pm or 6:36 pm.

    I want to convert 17.45 into a proper time format such that I get to see 5:45 pm.

    Is there a way I can do it in STATA?

    Thanks,
    Amit

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float time_out
    17.45
    18.36
    end
    
    tostring time_out, gen(str_time) format(%03.2f) force
    gen double proper_time = clock(str_time, "hm")
    format proper_time %tcHh:MM_AM
    The variable proper_time is what you are asking for.

    In the future, when showing data examples, please use the -dataex- command to do so, as I have done here. If you are running version 15.1 or a fully updated version 14.2, -dataex- 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-.


    Comment

    Working...
    X