Unable to open stata files

General help and assistance with jamovi. Bug reports can be made at our issues page: https://github.com/jamovi/jamovi/issues . (If you're unsure feel free to discuss it here)
Post Reply
neck_dvvp
Posts: 6
Joined: Wed Jul 05, 2023 4:29 pm

Unable to open stata files

Post by neck_dvvp »

Hello!

I'm using jamovi desktop version 2.3.26.0 and I want to import stata files, but when I try to do it, i get an error:
"Unable to open tuple index out of range"

What may be causing this?

Thanks in advance!
User avatar
MAgojam
Posts: 422
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: Unable to open stata files

Post by MAgojam »

Hey @neck_dvvp,
this looks like a Python msg.
It might be that you need to update your version of jamovi.
We are currently with 2.3.28 solid and 2.4.1 current.
However if you don't mind providing your Stata file I might take a look.

Cheers,
Maurizio
neck_dvvp
Posts: 6
Joined: Wed Jul 05, 2023 4:29 pm

Re: Unable to open stata files

Post by neck_dvvp »

Hi!
Thanks for the quick answer.

I updated my jamovi to version 2.3.28 and I get the same error.

Sorry but I can't provide my stata file. But i tried it with multiple stata files, all getting the same error. I also tried to open data via open and special import, with no changes.

Edit: I now tried with other files and it worked, it may be file specific, but what could cause this? The file opens in R and SPSS, just not jamovi

Thank you
User avatar
MAgojam
Posts: 422
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: Unable to open stata files

Post by MAgojam »

neck_dvvp wrote: Tue Jul 18, 2023 9:47 am Sorry but I can't provide my stata file...
Yes, I see!

So, since you know and use R, I'd suggest you try this:

Code: Select all

require(jmvReadWrite)
jmvReadWrite::convert_to_omv(fleInp = 'x:/Stata17/dta/auto.dta', fleOut = 'x:/jamovi/omv/auto.omv')
my_omv <- jmvReadWrite::read_omv(fleInp = 'x:/jamovi/omv/auto.omv')
head(my_omv)
The jmvReadWrite R package by Sebastian Jentschke of the jamovi Team is a Swiss army knife that could solve the problem.
You can download it from CRUN or Sebastian's repository here:
https://github.com/sjentsch/jmvReadWrite

I think it's superfluous to remind you to replace in the code, path and name of my file with yours, but I do :').
let me know what happens.

Cheers,
Maurizio
neck_dvvp
Posts: 6
Joined: Wed Jul 05, 2023 4:29 pm

Re: Unable to open stata files

Post by neck_dvvp »

Well, I wanted to give you good news, but that only fixed 3 of my files (which is already a starting point). The other 3 can't be converted, with the error message:

Code: Select all

The warning was: unable to translate '<stata_dta><header><release>118</release><byteorder>LSF</byteorder><K>[</K><N><b4>' to a wide string

Error in chkDtF(dtaFrm) : 
  Input data are either not a data frame or have incorrect (only one or more than two) dimensions.
I tried changing the usePkg argument to haven, which is what I was using originally in R, and it still did not work. All files have the same structure so I really don't understand what is happening.

Thank you for letting me know of that R package, it seems super useful! 😊
User avatar
MAgojam
Posts: 422
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: Unable to open stata files

Post by MAgojam »

neck_dvvp wrote: Wed Jul 19, 2023 9:20 am

Code: Select all

The warning was: unable to translate '<stata_dta><header><release>118</release><byteorder>LSF</byteorder><K>[</K><N><b4>' to a wide string
This tells us that it is .dta 118 format.
It went into effect with Stata 14 and is known as .dta Format 118.
It is also the primary format used by Stata 15 through Stata 18.
For datasets with more than 32,767 variables, Stata 15 through Stata 18 uses a slightly different format (the 119).
There are differences between operating systems, especially Win versus Mac or Linux.
Your files that don't pass are from which version of Stata with which operating system?
Have you tried adding encoding = "UTF-8" or encoding = "Latin1" inside the read_dta() function to tell R to import the same data without encoding it into numbers.

What happens with this code:

Code: Select all

require(jmvReadWrite)
require(rio)
my_dta <- rio::import("x:/Stata17/dta/auto.dta")
jmvReadWrite::write_omv(dtaFrm=my_dta, fleOut = 'x:/jamovi/omv/auto.omv')
my_omv <- jmvReadWrite::read_omv(fleInp = 'x:/jamovi/omv/auto.omv')
head(my_omv)
Without any .dta files where something happens I can't do much.
Cheers,
Maurizio
neck_dvvp
Posts: 6
Joined: Wed Jul 05, 2023 4:29 pm

Re: Unable to open stata files

Post by neck_dvvp »

Hello again!

Thank you so much for all the help!
Unfortunately I have no idea which Stata version these files are from, nor do I know which OS they were using. In theory, they should all have the same format and version, hence all my doubts.

Anyways, with the last code snippet you provided I was able to open every file successfully! Thank you so much!

I wish you the best
User avatar
sjentsch
Posts: 7
Joined: Wed Nov 06, 2019 2:34 pm
Location: Bergen, Norway
Contact:

Re: Unable to open stata files

Post by sjentsch »

Hei,

the only other suggestion I could possibly make is to open the respective files in Stata and to save it in a non-Stata-format: I never used Stata, so I don't know what export options are provided, but ideally sth. that R could read directly (i.e., RData, rds - if you want to keep some metadata - or CSV since that can be read by any software). This wouldn't be as easy as mass conversion using convert_omv, but would likely help you to import at least most of the data (missing some metadata such as labels, etc.).
The only other option you may try is readstata13 (https://cran.r-project.org/package=readstata13). I don't know to what degree it is using the same codebase as haven / ReadStat, but it may be worth a shot. You would need to adjust Maurizios R-code for that purpose.
It typically is impossible to do debugging without having data files to try out. However, in your case, the problem happens already when reading the file. That means, I anyway only would have had a very slight chance to solve your problem: What jmvReadWrite does is (primarily) to read and write jamovi-files (reading foreign formats is more for convenience, and relies on R-packages that I am not involved in).

Best regards, Sebastian
User avatar
jonathon
Posts: 2627
Joined: Fri Jan 27, 2017 10:04 am

Re: Unable to open stata files

Post by jonathon »

if you create an issue on our issues page, attaching the problematic files, we can take a look:

https://github.com/jamovi/jamovi/issues

jonathon
Post Reply