Convert a dta file to csv without Stata software
Solution 1
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!
Solution 2
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")
Solution 3
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:
Solution 4
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"
Solution 5
Another way of converting between pretty much any data format using R is with the rio package.
- Install R from CRAN and open R
- Install the
rio
package usinginstall.packages("rio")
-
Load the rio library, then use the
convert()
function:library("rio") convert("my_file.dta", "my_file.csv")
This method allows you to convert between many formats (e.g., Stata, SPSS, SAS, CSV, etc.). It uses the file extension to infer format and load using the appropriate importing package. More info can be found on the R-project rio page.
Related videos on Youtube
Brian
Updated on July 05, 2022Comments
-
Brian almost 2 years
Is there a way to convert a
dta
file to acsv
?I do not have a version of Stata installed on my computer, so I cannot do something like:
File --> "Save as csv"
-
Eli Bendersky about 14 yearsI'm sure there is a way. If the format of the .DTA file is specified, it can become a simple programming exercise
-
Brian about 14 yearsit's binary, I'm not sure how to get it out of there
-
-
eric.a.booth almost 14 yearsBTW, here is Stata's breakdown of how a .dta file is structured, which could be useful for extracting data elements: stata.com/help.cgi?dta
-
vsingh almost 11 yearsThis is paid but you can download to try out.
-
jhleath over 9 yearsNote that this technique does not work if you are utilizing Stata 13
.dta
files. You should utilize the techniques in this question. -
radek over 9 years@huntaub Thanks huntaub, updated answer to clarify that is 12 downwards.
-
Admin over 7 yearsI'm sure this works great for those already experienced with R, but for those who are not (like me), this will probably be frustrating. It took me an hour-plus of Googling and trial-and-error to figure out all the different packages you have to install before this actually works.
-
Matthew Vita almost 7 years@KennyLJ I'm new to R and found this to be very easy. Just ran
install.packages("rio")
and was good to go. -
Candamir over 6 yearsNote for the complete beginner: start with
library(haven)
-
dǝɥɔS ʇoıןןƎ over 6 yearsWow, I can't believe Pandas supports Stata :O
-
Nick Cox about 6 yearsI took the liberty of adding more information on dta versions.
-
Admin about 6 yearsThanks. I was surprised to see that these details are literally buried in source code so i thought to post them on here for others.
-
Nick Cox almost 4 yearsThey are not "literally buried in source code" but documented openly.
-
ancient geek over 3 yearsThis certainly worked for me. Very simple, can be done from command line, and totally free
-
shannontesla about 3 yearsThank you sooo much!