Announcement

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

  • Converting date to integer 0 and 1

    Hello,

    I have an int variable (not string; format %td) that presents date as "01jan1900". As this is not what I wanted and miscoded, I would like to convert this into integers such as 0,1,2,3. The codes I tried are as follows but they didn't work.
    Code:
    replace HVPN_E14_C64 = 0 if HVPN_E14_C64 =="31dec1899" type mismatch
    Code:
    gen  HVPN_E14_C64_real =real(HVPN_E14_C64)
    type mismatch
    Code:
    replace HVPN_E14_C64 = 0 if HVPN_E14_C64 ==31dec1899
    31dec1899 invalid name
    Your help will be appreciated. Thank you!

    Kind regards,
    Kim

  • #2
    you want the "td()" function; see
    Code:
    h td()
    or, more generally,
    h datetime

    Comment


    • #3
      Hello I found the answer from other post.
      Code:
      gen HVPN_E14_C64_1 = real(string(mofd(HVPN_E14_C64), "%tmCYN"))
      Thanks,

      Comment

      Working...
      X