Announcement

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

  • Convert Unix Timestamp into proper stata date format

    Hi everyone,

    I need to convert a Unix timestamp variable into a proper date variable, in format %td please. These dates will be used to match with others that have the same format.
    • Could anyone have an idea how to do that in stata please?
    Here is a small dataex:


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long(id fecha_alta fecha_baja)
    747107 1627776000 1640908800
    725268 1627776000 1640908800
    741860 1627776000 1640908800
    749574 1627776000 1640908800
    266011 1628294400 1630368000
    end


    Thank you in advance for your help.
    Best,

    Michael

    Edit: Date variables are expressed in -fecha_alta- and in -fecha_baja- variables.
    Last edited by Michael Duarte Goncalves; 16 Nov 2023, 02:20.

  • #2
    Code:
    help datetime software

    Comment


    • #3
      Hi Nick Cox,

      Thank you for your suggestion. Exactly what I needed!

      Code:
      generate contract_start = dofc(fecha_alta * 1000 + mdyhms(1,1,1970,0,0,0))
      generate contract_end   = dofc(fecha_baja * 1000 + mdyhms(1,1,1970,0,0,0))
      Lovely day.
      Best,

      Michael

      Comment

      Working...
      X