Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a dta file to csv without Stata software

Is there a way to convert a dta file to a csv?

I do not have a version of Stata installed on my computer, so I cannot do something like:

File --> "Save as csv"
like image 916
Brian Avatar asked Mar 29 '10 06:03

Brian


People also ask

How do I convert DTA to CSV?

Just open the . dta file in Stata and then export it as an Excel/CSV file (File >> Export >> Data to Excel spreadsheet(. xls)/Text data (delimited, . csv).

How do I open a DTA File on my PC?

Double-click on a Stata data file, which is a file whose extension is . dta. Note: The file extension may not be visible, depending on what options you have set in your operating system. Select File > Open... or click on the Open button and navigate to the file.

Is .DTA a Stata File?

The Stata_dta format (with extension . dta) is a proprietary binary format designed for use as the native format for datasets with Stata, a system for statistics and data analysis. Stata 1.0 was released in 1985 for the IBM PC. Stata is now available for Windows, Mac OS, and Unix.


4 Answers

The frankly-incredible data-analysis library for Python called Pandas has a function to read Stata files.

After installing Pandas you can just do:

>>> import pandas as pd >>> data = pd.io.stata.read_stata('my_stata_file.dta') >>> data.to_csv('my_stata_file.csv') 

Amazing!

like image 191
LondonRob Avatar answered Sep 24 '22 00:09

LondonRob


You could try doing it through R:

For Stata <= 15 you can use the haven package to read the dataset and then you simply write it to external CSV file:

library(haven) yourData = read_dta("path/to/file") write.csv(yourData, file = "yourStataFile.csv") 

Alternatively, visit the link pointed by huntaub in a comment below.


For Stata <= 12 datasets foreign package can also be used

library(foreign) yourData <- read.dta("yourStataFile.dta") 
like image 35
radek Avatar answered Sep 27 '22 00:09

radek


You can do it in StatTransfer, R or perl (as mentioned by others), but StatTransfer costs $$$ and R/Perl have a learning curve.
There is a free, menu-driven stats program from AM Statistical Software that can open and convert Stata .dta from all versions of Stata, see:

http://am.air.org/

like image 24
eric.a.booth Avatar answered Sep 25 '22 00:09

eric.a.booth


I have not tried, but if you know Perl you can use the Parse-Stata-DtaReader module to convert the file for you.

The module has a command-line tool dta2csv, which can "convert Stata 8 and Stata 10 .dta files to csv"

like image 21
ghostdog74 Avatar answered Sep 26 '22 00:09

ghostdog74