Skip to content
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

Stata %d formatted dates not read as dates #130

robkar opened this issue Nov 2, 2015 · 1 comment

Stata %d formatted dates not read as dates #130

robkar opened this issue Nov 2, 2015 · 1 comment


Copy link

@robkar robkar commented Nov 2, 2015

I got a Stata data file using "%d" as the format for date variables, which haven (current devel version) interpreted as numeric rather than dates. According to a Stata FAQ this seems to be a valid (but old?) date format.

The foreign package does convert the variable to an R Date.

Example file: dateformat.dta

> library(haven)
> library(foreign)
> read_dta('dateformat.dta')
1 20394
> read.dta('dateformat.dta')
1 2015-11-02
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 15.10

 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] foreign_0.8-66   haven_0.2.0.9000

loaded via a namespace (and not attached):
[1] Rcpp_0.12.1

Copy link

@hadley hadley commented May 30, 2016

Fixed in 44e9d5b. Thanks for the test data!

@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.
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants