Announcement

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

  • clock time

    hi,
    i currently have a time recorded as:

    11:30
    15:30
    8:02
    23:36

    They are in string. How do I convert so that I can easily analyze? i.e. I need to know which events occurred between 20:00 and 7:00.

  • #2
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str5 str_time
    "11:30"
    "15:30"
    "8:02"
    "23:36"
    end
    
    
    gen double stata_time = clock(str_time, "hm")
    format stata_time %tcHH:MM
    
    gen byte wanted = inrange(stata_time, tc(07:00:00), tc(20:00:00))
    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 18, 17, 16 or a fully updated version 15.1 or 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.

    Comment


    • #3
      Between 20;00 and 7:00 I interpret as 20:00 or later or 07:00 or earlier (but do you really mean 06:59)? On this reading Clyde Schechter's result should be negated logically. That is, you want

      Code:
      !inrange()

      Watch out for

      times 24:00 to 24:59

      hours without minutes

      and other pathologies.

      Comment

      Working...
      X