New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write_dta: dates are off by 10 years #139

diogocp opened this Issue Nov 30, 2015 · 2 comments


None yet
2 participants
Copy link

diogocp commented Nov 30, 2015


df <- data.frame(date = as.Date("2015-11-30"))
write_dta(df, "date-test.dta")

When I open date-test.dta in Stata, the variable has the value 16769. After I apply the %td format, Stata shows it as 29nov2005.

Interestingly, read_dta is working correctly. Reading that same file back into R gives me the date 2005-11-29 (as long as I save it in Stata after format %td, otherwise it is read as a double).

Stata stores dates as "days since 01jan1960 (01jan1960 = 0)".


This comment has been minimized.

Copy link

diogocp commented Nov 30, 2015

I don't know much about Rcpp, but I think the problem is here:

Dates go into that branch and are coerced to numeric using the R epoch. They need to be handled separately. Unfortunately, there is no specific SEXPTYPE for Dates.

Any ideas?


This comment has been minimized.

Copy link

hadley commented May 30, 2016

Done in 944466b

@hadley hadley closed this May 30, 2016

@lock lock bot locked and limited conversation to collaborators Jun 27, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.