Description Usage Arguments Details Value Author(s) References See Also Examples
Converts numeric values corresponding to a Stata date-time format to a Date or POSIXct object.
1 | fromStataTime(x, fmt, tz = "")
|
x |
numeric. |
fmt |
character. Stata date-time format: '%tc', '%tC', '%td', '%tm', '%tq', '%th', '%tg', or '%ty'. |
tz |
character. Time zone. |
Stata stores dates-time variables as units of time since Jan 1, 1960. The unit of time used depends on the Stata format. One unit in variable formatted '%tc', corresponds to 1 millisecond; in '%td', one day; in '%tm', one month, etc.
This function is useful for converting date-time variables imported from a Stata dataset, such as from read.dta or read.stataXml, into the correct R dates values.
Stata does not use time zones in date-time values. If a time zone is important for conversion, supply a time zone in the tz argument.
The Stata '%tC' format includes leap seconds. Since R does not use leap seconds in the POSIXt classes, values of leap seconds are handled according to the POSIX standard when converting '%tC' values to POSIXct.
If fmt is '%tc' or '%tC', then a POSIXct object is returned. If fmt is '%td', '%tm', '%tq', '%th', then a Date object is returned. If fmt is '%tg' or '%ty', then a numeric object object is returned.
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | ## clock to POSIXt
fromStataTime(-1:1, '%tc')
## dates to Date
fromStataTime(-1:1, '%td')
## months
fromStataTime(-1:1, '%tm')
## quarters
fromStataTime(-1:1, '%tq')
## half-years
fromStataTime(-1:1, '%th')
## years
fromStataTime(1959:1960, '%ty')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.