asStataTime: Convert R date-time classes to Stata date-times

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Converts R date and time classes (chron, Date, POSIXt, yearmon, yearqtr) to a numeric value corresponding to the most similar Stata date/time format.

Usage

1
asStataTime(x, useTc = TRUE)

Arguments

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.

Details

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

Value

numeric vector. The vector has a single attribute stata.format: a character string with the Stat format.

Author(s)

Jeffrey Arnold

References

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.

See Also

fromStataTime, Date, POSIXt, yearmon, yearqtr

Examples

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)

jrnold/stataXml documentation built on May 20, 2019, 2:06 a.m.