# Import an RDATA, SPSS, SAS, or STATA file into Mathematica

I would like to import the World Value Survey data file into Mathematica, but it's only given in spss, sas or stata formats, which are statistical analysis softwares format I think.

I can't get to import these files in Mathematica, they are not recognized.

I've found a Wolfram executable that should allow me to import SAS files but it can't make it work on Linux. Have you already been able to import such files in Mathematica?

-
@MarcoB As in the original question, the idea was to get the data from World Value Survey, in any of the forms available in the Longitudinal Data Files, i.e R, SAS, SATA, SPSS, but I would not discard retrieving particular variables directly from the web. – rhermans May 26 '15 at 7:19
Its frankly bizzare that the data dictionary is available in excel but the actual data isn't - at least it would be more universal than any of the other formats.. Have you tried mailing them and suggesting supporting at least one non-proprietary format should be strongly considered? – Gordon Coale May 26 '15 at 7:53
Looks like the quickest way is to download R and use this code here to export to CSV. Since you only need to do it as a once off there is very little point in messing around with Rlink. – Gordon Coale May 26 '15 at 7:57
@GordonCoale R is bundled with Mathematica and can be called with the RLink package. – Sjoerd C. de Vries May 27 '15 at 11:12
@rhermans - working on it but never used Rlink before ;) – Gordon Coale May 29 '15 at 11:28

This should do the trick - disclaimer the file is 1.4Gb so everything takes a veerryyy long time on my MacBook air, and you will need an active internet connection for InstallR to work. Note you have to escape \ internal R file paths and anything else that uses a double quote.

Needs["RLink"];

InstallR[];

REvaluate[

(*{".Traceback","WVS_Longitudinal_1981_2014_R_v2015_04_18"}*)


Writes the data into an R Dataset called WVS_Longitudinal_1981_2014_R_v2015_04_18

REvaluate["write.csv(WVS_Longitudinal_1981_2014_R_v2015_04_18,file=\


Writes the data back out to a CSV. Note in this case the file is a simple tabular one. This might be more problematic for some of the more complex data structures that .rdata format permits.

Theoreticall you can actually import the WVS_Longitudinal_1981_2014_R_v2015_04_18 data directly into MMA and work with it natively from that point but requires me working through the rLink tutorial a bit more than I have time for right now. :)

EDIT : Some useful tips to explore the data directly.

Get Column Names

REvaluate["names(WVS_Longitudinal_1981_2014_R_v2015_04_18)"] // Short


Get a single column in this case S001

REvaluate["WVS_Longitudinal_1981_2014_R_v2015_04_18\$S001"]


Get the first 10 lines of the R data.frame note the R data objects in there. head is like the unix head not Head[] This data is so wide and deep its hard to get it in a readable format without subsetting and slicing and dicing.

REvaluate["head(WVS_Longitudinal_1981_2014_R_v2015_04_18,n=10)"]

-

You are right - those formats are for statistical software packages.
I've noticed in Big Data discussions that Mathematica does not want to extend the range of acceptable data formats leaving the job to third-party software. I would recommend to use software like 'Stat/Transfer', which is a usual practice for such tasks. If you take data from WVS, say Stata's .dta which I prefer, you may easily transfer it to .CSV or .DAT file.
Just take an option ASCII - Delimited as shown below.
Then .csv is imported to Mathematica as usual.
Another option is to use ASCII Fixed Format + All Programs which will produce .dat` file also easily imported to Mathematica (I've checked both cases).

-
Thanks for the answer, 'Stat/Transfer' unfortunately its a paid software. – rhermans May 26 '15 at 7:24
I'm not aware about free analogs, indeed - it is very specific stuff and works fine. – garej May 26 '15 at 14:47