Announcement

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

  • Creating a single datetime variable out of two variables

    Dear forum users,

    I am using a large dataset which stores ‘dates’ in a string variable (e.g. 2021-01-05) and ‘times’ in a separate variable (e.g. 23:25).

    Can somebody advise how I can create a single datetime variable using information stored in the date and time variable?

    Best wishes,
    Hannes

  • #2
    Code:
    clear
    input str15 date str7 time
    "2021-01-05" "23:25"
    end
    
    gen double wanted= clock(date+"-"+time, "YMDhm")
    format wanted %tc
    Res.:

    Code:
    
    . l
    
         +-----------------------------------------+
         |       date    time               wanted |
         |-----------------------------------------|
      1. | 2021-01-05   23:25   05jan2021 23:25:00 |
         +-----------------------------------------+
    Last edited by Andrew Musau; 08 Apr 2022, 05:45.

    Comment

    Working...
    X