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

written dta file not readable in Stata #461

Closed
JoWi2 opened this issue Jul 3, 2019 · 5 comments

Comments

@JoWi2
Copy link

@JoWi2 JoWi2 commented Jul 3, 2019

When writing a .dta file using haven, it can be opened with Stata MP (the most expensive version of Stata with the most features).

I checked with an MWE:

library(haven)
foo <- mtcars #using mtcars with 32 observations of 11 variables
write_dta(foo, "C:/Users/XXXX/Desktop/foo.dta", version = 15) # writing the data frame into a dta file

When opening the file in Stata (the first line - use... - is the Stata command, the rest is basically the error message), I get

use "C:\Users\XXXX\Desktop\foo.dta"
dataset too large
This .dta file format was created by Stata/MP and has more variables than your
Stata can handle.
r(459);

This is clearly not the case. So if this problem could be resolved in haven, that would be much appreciated!

@kuriwaki

This comment has been minimized.

Copy link

@kuriwaki kuriwaki commented Jul 7, 2019

I get an error as well, but with the following StataMP (version 15.1) error message. Below is the Stata code:

/* mtcars saved in write_dta with version = 14 can be read in by Stata */
use "https://www.shirokuriwaki.com/datasets/mtcars_haven_stata-14.dta"

/* but the same thing with version = 15 cannot */
use "https://www.shirokuriwaki.com/datasets/mtcars_haven_stata-15.dta"
* .dta file corrupt
* The marker </sortlist> was not found in the file where it was expected to be.  This
*  means that the file was written incorrectly or that the file has subsequently become
* damaged.
* r(688);

Importantly, this only happens when version = 15 in write_dta. I can open the dta fine when version = 14 (the default) or any other version value from 8 to 14.

@LulinS

This comment has been minimized.

Copy link

@LulinS LulinS commented Jul 22, 2019

Same errors. Appreciated if it can be solved.

@kuriwaki

This comment has been minimized.

Copy link

@kuriwaki kuriwaki commented Jul 22, 2019

I updated above my comment so the error is reproducible by copy-pasting the snippet into Stata. The online datasets I read from are two that I generated in haven. Hope it helps.

@evanmiller

This comment has been minimized.

Copy link
Collaborator

@evanmiller evanmiller commented Oct 27, 2019

Thanks for the report. It appears that the integer size of column indexes changed with Stata 15. I'll have a fix of some sort soon.

evanmiller added a commit to WizardMac/ReadStat that referenced this issue Oct 27, 2019
@hadley

This comment has been minimized.

Copy link
Member

@hadley hadley commented Nov 6, 2019

I've updated the version of readstat embedded in haven, so this should be fixed in the development version. Please let me know if not.

@hadley hadley closed this Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.