4

I am trying to read a Stata (.dta) file in Python with pandas.read_stata, But I'm getting this error:

ValueError: Version of given Stata file is not 104, 105, 108, 111 (Stata 7SE), 113 (Stata 8/9), 114 (Stata 10/11), 115 (Stata 12), 117 (Stata 13), or 118 (Stata 14)

Please advise.

3
  • 2
    Do you mean .dta?
    – Nick Cox
    Commented Nov 1, 2017 at 14:24
  • Yes .dta files :-) , typed mistake
    – Naga kiran
    Commented Nov 2, 2017 at 5:50
  • If you examine a Stata .dta file in a text editor, the first characters will be something like <stata_dta><header><release>118</release> and the release must be one of the values given in the read_stata error message.
    – user4690969
    Commented Nov 15, 2017 at 19:11

2 Answers 2

3

If the version of your .dta file is 110 or something else that is not supported by pandas, you can easily use pyreadstat python library. This module is a wrapper around the excellent Readstat C library.

The great thing about pyreadstat is that the library returns pandas dataframe. Here is the snippet:

import pyreadstat    
dataframe, meta = pyreadstat.read_dta('Filepath.dta')
1

Just use the read_table() of Pandas then make sure to include delim_whitespace=True and header=None.

3
  • I tried, i got error of CParserError: Error tokenizing data. C error: Expected 8 fields in line 5, saw 18 , the data is congested i think, delim_whitespace may not work.
    – Naga kiran
    Commented Nov 6, 2017 at 7:20
  • Can you open the file in the notepad and see how the data there looks like? Is it csv?
    – Panda_Pen
    Commented Nov 6, 2017 at 9:25
  • Yeah, i opened it, It is not a comma seperated. It may seperated by some special characters and symbols .
    – Naga kiran
    Commented Nov 6, 2017 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.