Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • R date and datetime conversion

    I may be being obtuse but it seems to me that there is an error in the datetime_software help & manual information on converting from R dates to Stata dates - and, equivalently, from R to Stata datetime values.

    R uses the Unix convention of an epoch beginning on 01jan1970 00:00:00, The help information says that to convert from R dates to Stata dates use:

    Code:
    generate statadate = rdate - td(01jan1970)
    which implies: rdate = statadate + td(01jan1970) or rdate > statadate since td(01jan1970) must be positive as the Stata epoch starts on 01jan1960 - in fact td(01jan1970) is 3653. This must be wrong since any R date must be less than the equivalent Stata date as the R epoch starts later than the Stata epoch. Hence, I think that the correct conversion is:

    Code:
    generate statadate = rdate + td(01jan1970)
    I would hope that few have actually been misled by the apparent mistake, but it might be best to correct it in both the [D] manual and the help information.
Working...
X