Description Usage Arguments Details Value Author(s) References See Also Examples
Converts R date and time classes (chron, Date, POSIXt, yearmon, yearqtr) to a numeric value corresponding to the most similar Stata date/time format.
1 | asStataTime(x, useTc = TRUE)
|
x |
chron, Date, POSIXt, yearmon, or yearqtr object. |
useTc |
If TRUE, use the '%tc' format for converting POSIXt objects. Otherwise, use the '%td' format for POSIXt object. The '%tc' format was introduced in Stata 10, so set this to FALSE to ensure compatibility with earlier versions of Stata. |
Stata stores date-time variables as a number of time units since 1960-1-1. The number of units depends on the format: milliseconds for '%tc', days for '%td', months for '%tm', quarters for '%tq', half-years for '%th'. asStataTime converts to following R data-time classes to their most similar Stata date-time format
chron | %td |
Date | %td |
POSIXct | %tc or %td |
POSIXlt | %tc or %td |
yearmon | %tm |
yearqtr | %tq |
numeric vector. The vector has a single attribute stata.format: a character string with the Stat format.
Jeffrey Arnold
For details of how Stata represents dates and times, see Stata help for dates_and_times, online at http://www.stata.com/help.cgi?dates_and_times.
fromStataTime
, Date
, POSIXt
,
yearmon
, yearqtr
1 2 3 4 5 | ## Date
asStataTime(as.Date('1960-1-1') + -1:1)
## POSIXct
asStataTime(as.POSIXct('1960-1-1 00:00:00') + -1:1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.