A simple recipe for converting Stata data into CSV. CSV stands for comma separated value. Common uses for this recipe is when you want to move information from Stata into a spreadsheet or another database. In this example, we assume in Stata input file name is called “MyStata.dta” and the resulting CSV file name is “MyStata.csv”.
Here is the process.
Install R (if its not already installed)
$ sudo apt-get install r-base-core
Now run R from the folder where your Stata (.dta) files lives.
You should see something like this:
R version 2.14.1 (2011-12-22) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. >
Import the foreign library
Import the Stata data
> MyData <- read.dta("MyStata.dta")
Now write the information out to a CSV file using write.csv()
write.csv(MyData, file = "MyStata.csv")
Now you have your CSV file.