Announcement

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

  • Extract samples for a specific time period

    I have a dataset of GPS with timestamp variable.
    I would like to extract observations that do not have timestamps between 0am and 5am in stata.
    i tried the following command but it didnt work.

    drop if ! (hours(my_timestamp_variable)>=0 & hour(my_timestamp_variable)<5

    I also tried the command below, but didnt work as well.
    drop if ! my_timestamp_variable>=tc("09oct2013 00:00:00") & my_timestamp_variable<tc("09oct2013 05:00:00")

    my_timestamp_variable is like as below after conversion using the following commands.
    my_timestamp_variable: "09oct2013 00:00:00"
    command: format v6 %tc

    Thank you very much for your help in advance.
    Best regards,
    Last edited by Hana Nikai; 24 Jan 2024, 03:19.

  • #2
    Code:
    clear
    input double time
    2021685900000
    2021718600000
    2021690400000
    2021754300000
    2021691600000
    end
    format time %tc
    
    gen wanted = !(inrange(hh(time), 0, 4)| hh(time)==5 & !mm(time))
    Res.:

    Code:
    
    . l
    
         +-----------------------------+
         |               time   wanted |
         |-----------------------------|
      1. | 24jan2024 03:25:00        0 |
      2. | 24jan2024 12:30:00        1 |
      3. | 24jan2024 04:40:00        0 |
      4. | 24jan2024 22:25:00        1 |
      5. | 24jan2024 05:00:00        0 |
         +-----------------------------+
    
    .
    See

    Code:
    help datetime

    Comment


    • #3
      Mr.Andrew Musau
      Thank you very much! i noticed that the command "hours" should be replaced with "hh".
      I also succeeded with the commands as below.

      drop if !(hh(v6)>= 0 & hh(v6)<5)

      thank you very much for your help!!

      Comment

      Working...
      X