Home   Publications   Resources   My CV   Contact   RSSRSS

Loading SPSS (.sav) into Stata

October 12, 2012 by Daniel Marcelino | Filed under Tutorials.

Most statistical softwares nowadays are able to convert their files to a wide range of other packages. Perhaps it is the reason for the discontinuity of old converter bundles like SAS Transport and DBMS. Interesting, however, Stata, a quite popular statistical package, still lack built-in support for exporting and importing files among concurrent softwares like SPSS and JMP. Things can be even worse if one needs to translate files to-or-from minor packages like Octave, HLM, and Statistica, for instance. Recently, user-written algorithms came up to help Stata users to overcome such a gap. This user-wrapper named UseSPSS was written by Sergiy Radyakin. Nonetheless, there are still limitations on the version of SPSS you can load into Stata. [Edited] As Sergiy Radyakin himself commented bellow, the limitations are related to the Stata support and not to the UseSPSS bundle.

A good news is that R provides a library named “foreign” that can translate files virtually from one to any other software. That is, you can simply load a file into R and then export to any other format. You are not limited to Excel(r) and text files like .txt, dat, and .csv. Hence, even if you don’t know how to handle analysis using R, you can use this free-for-all yet robust package to translate files to your favour statistical software. You can actually save more than $180 with licensing a version of the StatTranfer, in my opinion, the best file converter available in the market. The StatTransfer itself also explains why Stata supplies so little functions to import and export files.
In what follows I show step-by-step how to use R to translate files from SPSS into Stata format for free.
Step 1: install R from
Once you have installed R you can import a file and export it straightforwardly to many other packages, or just convert to universal .txt. I will comment one way (for dummies) to proceed in the following paragraphs.
Step 2: install the package Rcmdr from the Package Menu by selecting “Install Packages” or by typing:

install.packages("Rcmdr", dep = TRUE)


Step 3: open up the Rcmdr package by evoking it typing:


require(Rcmdr)

Step 4: When Rcmdr loads it should load a new window–the R Commander window. Then, select from the menu Data -> Import Data -> from SPSS data set. Name your data set as you like and select ‘ok’. Now you must find your .sav file.
An alternative you may know is doing by hand without Rcmdr window interface as in the following:
require(foreign)
yourdata = read.spss(file.choose(), use.value.labels = FALSE, to.data.frame = TRUE)

This command will setup variables to not convert value labels. Which may optimize the cleaning task for later analysis. In addition, the second statement assure the data will remain as a rectangular table rather than converting to lists, vector or matrixes.
Step 5: If there has been no problem up to now you should have a data set in the memory. You can check it doing some tabulation or just typing:
head(yourdata)
tail(yourdata)

Finally, you can export the data to Stata (.dta) with the next command:
write.dta(yourdata, "yourdata.dta")
It is done and you can check out your new file in your home directory. If you don't know where is your home directory, just type in the R window getwd(), it will print the path to you. Finally, there are many specifications you might want to arrange when loading or saving you files. Just learn more about it by typing ?foreign in the prompt of R.


Tags: , , , ,

3 Responses to “Loading SPSS (.sav) into Stata”

  1. Sergiy Radyakin says:

    UseSPSS does not impose any restriction on the version of SPSS, but is constrained primarily by the limits of Stata, specifically lack of support of long strings (more than 244 characters) and lack of Unicode support.If you have a file that can't be read and the reason is not any of the above limitations, do not hesitate to contact me using the email specified in the usespss.hlp file. Similarly if there is any useful feature present in the foreign package that you think is absent in UseSPSS let me know. UseSPSS supports SPSS *.sav files from Windows, Mac, Unix and other platforms, with and without compression,etc. The comment "Windows only" refers to UseSPSS and not the version of the data. Hope this helps.

    Best, Sergiy

  2. Daniel says:

    Thanks for your clarification Sergiy Radyakin. I will take a time to look at both bundles to figure out the capabilities of your program and that offered by the foreign package. Then I can send you a private message.

  3. max bw says:

    I like this post, enjoyed for putting up.

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax