Message Boards Message Boards

4 Replies
3 Total Likes
View groups...
Share this post:

Importing STATA files

Posted 11 years ago
Hi there!

How can I import .dta files in Mathematica?

My current approach is first reading the .dta in R, exporting as csv, and then reading the .csv in Mathematica. I wish I could import directly.
Is this possible?

A random  .dta file may be downloaded from here:
POSTED BY: Sandu Ursu
4 Replies

With Mathematica 12 it's very easy to import Stata files with the Import[] command. See:

So, this might not work perfectly, but why not leverage RLink?


If you now look at rf, you will see that it has three parts, including an evocative second part with the header RData.  If we then try this:

     Transpose[List @@ rf[[2]]]

We get something that sure looks like the data you want.  

I don't vouch that this is (a) the best way or (b) works for all forms of .dta files (about which I know nothing), but since R knows what to do with .dta files and Mathematica now speaks to R, why not put the two together?

POSTED BY: Seth Chandler
I think Seth is right - it is a good idea to use R link. Same idea but more generally can be found here - togethere with a few other ones: Convert dta file to CSV
POSTED BY: Sam Carrettie

I am trying to read .dta with RLink as suggested by Seth but Mathematica doesn't seem to acknowledge the package I want to use.

I want to use the read.dta13 from the readstata13 package.

InstallR["RHomeLocation" -> "C:\\Program Files\\R\\R-3.4.1"]

Mathematica returns the following error: there is no package called 'readstata13'.

Am I missing a step after installing a package? Maybe I need to reference it before using it.


Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract