Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to read stata .dta file in python

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.

like image 454
Naga kiran Avatar asked Oct 15 '25 04:10

Naga kiran


1 Answers

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')
like image 179
Mohammad Reza Malekpour Avatar answered Oct 16 '25 16:10

Mohammad Reza Malekpour



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!