Link to home
Start Free TrialLog in
Avatar of magento
magento

asked on

Stata conversion DTA to CSV

Hi,

How can I convert old version of dta file to excel or csv file. (doing it for my friend)
I checked in GitHub for all Stata file reader and for old version nothing is there.

please advice.

Error  for reference
[code]  
File "/home/pi/.local/lib/python3.7/site-packages/pandas/io/stata.py", line 1299, in _read_old_header
    raise ValueError(_version_error.format(version=self.format_version))
ValueError: Version of given Stata file is 32. pandas supports importing versions 105, 108, 111 (Stata 7SE), 113 (Stata 8/9), 114 (Stata 10/11), 115 (Stata 12), 117 (Stata 13), 118 (Stata 14/15/16),and 119 (Stata 15/16, over 32,767 variables).
[/code]

code used:
[code]
import pandas as pd
reader=pd.read_stata("DP.DTA",chunksize=100000)
df = pd.DataFrame()
for itm in reader:
    df=df.append(itm)
df.to_csv("DP.csv")
[/code]

Sample dta file attached.
DP.zip
ASKER CERTIFIED SOLUTION
Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of magento
magento

ASKER

Hi Leonidas,

I tested it, its working .
But csv file doesnt looks like what i was expecting.
May be i need to check in windows machine , will update you next week.

Many thanks for the help.

Thanks,
Magento
Avatar of magento

ASKER

Thanks for the help.