savespss will export data from Stata's memory into an SPSS system (aka binary file) datafile (*.sav).
If instead you want to import SPSS data to Stata, then you need the -usespss- program
savespss facilitates exchange of data between Stata and SPSS. SPSS does not support direct import of datasets in recent Stata formats. Reportedly formats up to Stata 9 are supported by SPSS's import facility. SPSS of versions prior to 14.0 could not import Stata's datasets at all.
This program solves this by allowing Stata users and programmers to export their data directly in SPSS system file format.
The description of assumptions and limitations is organized into the following sections:
savespss supports all the data attributes that the users normally expect from a statistical data conversion package, but be sure to also check the non-supported features.
List of supported features:
savespss supports all the data attributes that the users normally expect from a statistical data conversion package, but there are naturally some limitations.
List of [currently] not supported features:
Savespss is part of Statistical Software Components (SSC). Individual files are available from this RePEc page. Most users don't need to download individual files and can install with a single command.
To install -savespss- type in Stata:
then follow the link to install the program.
Note: check with SSC regularly to receive further updates!
If you installed a beta version of savespss from this site and not from SSC earlier, uninstall the beta version and reinstall from SSC.
savespss is implemented in Mata programming language and requires Stata version 10.0 or later. It is platform-independent and designed to work equally well in Windows, MacOS, and Linux environments.
savespss is a genuine writer. It does write the data into SPSS binary format without any need for additional packages or converters. In particular, it doesn't require SPSS (PASW) or StatTransfer to be installed on the user machine.
The main syntax is trivial:
will show information about the program and ask for filename to export the current data from memory.
will export the current data to the specified file. Specify full path if necessary.
savespss "datafile.sav", extmiss("97 98 99")
will export the current data to the specified file, recoding the extended missing values .a, .b, and .c to 97, 98, and 99 respectively for all numeric variables. If option extmiss is not specified, the 'convenient' values will be detected automatically, based on the user data. This takes a bit of time.
From the version 1.73 the extended missing values can not be suppressed as in the earlier version alltogether by specifying an option extmiss("off"). This option is also not available in the dialog. This option is likely to return in a future version.
To convert a datafile the following sequence can be used:
use "C:\DATA\mydata.dta" savespss "C:\DATA\mydata.sav"
If desired, an option replace can be added to allow overwriting existing file.
For non-ASCII content, option codepage can be used:
savespss "C:\Data\mydata.sav", codepage(1254)
In Stata 13 and newer a strlmax() option may be added to limit the length of strings. This option may be necessary to prevent the output file growing uncontrollably or when it is known the long content will not be required.
Options if and in were frequently requested. I am still investigating, but for now a second, extended version of the dilog exists, which provides these options:
Note that SPSS software blocks data files that it opens for write access by other programs. You will get an error if you attempt to write (export) data to the file currently open in SPSS on your system. This is normal by-design operation (of SPSS) and is not a bug of either side.
Stata as of version 13.1 does not support unicode for strings that it processes, including variable and value labels, and variable names. Hence the string contents is saved as ASCII content.
An option codepage can be specified to instruct savespss to apply a certain codepage to the strings in output. This option must be specified by the user directly since Stata does not contain it neither for the dataset in memory nor for the files saved to disk.
The term codepage refers to interpretation of characters with codes 128-255.
Option codepage takes values from the following list:
savespss "C:\Data\mydata.sav", codepage(1254)
Only one codepage may be specified for each one file and it will be applied to all strings in that file.
Note, that the default codepage is: 1252 (Latin-1).
Let's consider the standard example of auto.dta dataset. Here is how it looks in Stata 10:
sysuse auto browse
Save it to SPSS system file format (auto.sav):
And view the result in the PSPP. Here is the data:
Here is the data with value labels:
And here are the variables.
And here is how it is described: PSPP output
savespss was written by Sergiy Radyakin.
To contact the author send email to: sradyakin/at/worldbank.org.
Or write your questions to Statalist with tag savespss (preferred)
|01 Sep 2014||1.77||this revision fixes the problem with dialog file not installed, fixes problem with declared but missing value labels reported by Ellen Van Loo, and behaves more intelligently with respect to extended missing values in the original file.|
|30 Jul 2014||1.73||the first version published to SSC; this revision includes support of strLs, dates conversion, better reporting on the recoding of missing values, enhanced dialog, and other improvements; it also fixes the issue with long value labels reported by Daniel Bela|
|07 Jul 2014||1.61||experimental support of output in codepages (requested by Alexander Staudt)|
|28 Jan 2014||1.51||experimental support of long string variables (Stata 13)|
|27 Jan 2014||1.22||fixed problem reported by P.H.E. van Rooij (thank you) with exporting datasets containing numeric variables that are completely missing observations.|
|25 Oct 2013||-||fixed program from freezes under an identifiable rare condition.|
|22 Oct 2013||-||added autodetection of 'convenient' values for extended missings|
|21 Oct 2013||-||fixed problem reported by Dr. Dirk Enzmann regarding buffer overflow under some conditions. Thank you!|
|21 Oct 2013||-||fixed recurrently appearing dialog|