• Laura Whiting

Getting Started in Stata - Converting Date-Time Variables

Stata stores dates in numeric form using an elapsed-time format. A date variable is interpreted by Stata as the number of days since 1 January 1960. For example: 0 = 1 January 1960; 1 = 2 January 1960; -1 = 31 December 1959.


Time and date-time variables are also stored numerically, however Stata interprets these as the number of milliseconds since 1 January 1960. For example: 0 = 1 January 1960 at 00:00:00.000; 1 = 1 January 1960 at 00:00:00.001; -1 = 31 December 1960 at 23:59:59.999. A time-only variable is formatted such that 1 January 1960 is not shown.


Often when you are first importing or loading a dataset in Stata you will find your date-time variables are stored as strings. There is a range of Stata commands designed to help you convert these string date-times into the appropriate Stata numeric variable. You can use the following cheat sheet to help you work out which commands you need to use and how to format them.

Stata Date-Time Cheat Sheet
.pdf
Download PDF • 36.66MB

© 2020 by Survey Design and Analysis Services. 

  • LinkedIn
  • Facebook
  • Twitter
  • YouTube