= Stata Datetime Pseudo-Functions = Stata supports these '''datetime pseudo-functions functions''' in the global scope. <> ---- == Tc == Create a value representing the number of milliseconds since the Stata epoch (`01jan1960 00:00:00.000`). There are two functions: '''`tc`''' and '''`tC`'''. To create a datetime that ''ignores'' leap seconds, try `tc(01jan1960 00:00:00.000)`. To create a datetime that ''includes'' leap seconds since the epoch, try `tC(01jan1960 00:00:00.000)`. === Converting SPSS Dates and Datetimes === The `tc` pseudo-function can be used to normalize dates and datetimes that are imported from [[SPSS]]. SPSS represents dates ''and'' datetimes are the number of seconds since the SPSS epoch (`14oct1582 00:00:00`), ignoring leap seconds. Therefore, to normalize an SPSS date or datetime, convert seconds to milliseconds and add `tc(14oct1582 00:00)`. {{{ generate double datetime_stata = (datetime_spss * 1000) + tc(14oct1582 00:00:00) format datetime_stata %tc }}} === Converting R Datetimes === Very similarly, the `tC` pseudo-function can be used to normalize datetimes that are imported from [[R]]. R represents datetimes as the number of UTC-adjusted milliseconds since the Unix epoch (`01jan1970 00:00:00`). Therefore, to normalize an R datetime, subtract `tC(01jan1970 00:00:00)`. {{{ generate double datetime_stata = datetime_r - tC(01jan1970 00:00:00) format datetime_stata %tC }}} ---- == Td == To create a value representing the number of days since the Stata epoch (`01jan1960 00:00:00.000`), try `td(01jan1960)`. === Converting R Datetimes === The `td` pseudo-function can be used to normalize dates that are imported from [[R]]. R represents dates as the number of days since the Unix epoch (`01jan1970 00:00:00`). Therefore, to normalize an R date, subtract `td(01jan1970)`. {{{ generate long date_stata = date_r - td(01jan1970) format date_stata %td }}} ---- == Th == To create a value representing the number of half years since the Stata epoch (`01jan1960 00:00:00.000`), try `th(1960-h1)`. ---- == Tm == To create a value representing the number of months since the Stata epoch (`01jan1960 00:00:00.000`), try `tm(jan1960)`. ---- == Tq == To create a value representing the number of quarters since the Stata epoch (`01jan1960 00:00:00.000`), try `tq(1960-q1)`. ---- == Tw == To create a value representing the number of weeks since the Stata epoch (`01jan1960 00:00:00.000`), try `tw(1960-w1)`. ---- == Ty == To create a value representing the number of years since the Stata epoch (`01jan1960 00:00:00.000`), try `ty(1960)`. ---- CategoryRicottone