savespss - a module to export Stata data into SPSS system file format (*.sav)

Note: this page is under construction and may be updated frequently in 2013-2014

[Last update: 01 Sep 2014 00:00 EST 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. The version is now 1.77.]
[Before: 30 Jul 2014 15:57 EST 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; the version is now 1.73]
[Before: 07 Jul 2014 14:55 EST experimental support of output in codepages (requested by Alexander Staudt), version is now 1.61]
[Before: 28 Jan 2014 23:19 EST experimental support of long string variables (Stata 13), version is now 1.51]
[Before: 27 Jan 2014 20:36 EST fixed problem reported by P.H.E. van Rooij (thank you) with exporting datasets containing numeric variables that are completely missing observations; version is now: 1.22]
[Before: 25 Oct 2013 12:14 EST fixed program from freezes under an identifiable rare condition.]
[Before: 22 Oct 2013 22:51 EST - added autodetection of 'convenient' values for extended missings]
[Before: 21 Oct 2013 22:15 EST - fixed problem reported by Dr. Dirk Enzmann regarding buffer overflow under some conditions. Thank you!]
[Before: 21 Oct 2013 15:30 EST - fixed recurrently appearing dialog]

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

Description

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:

Installation instructions

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:

findit savespss
then follow the link to install the program.

Note: check with SSC regularly to receive further updates!

adoupdate savespss
If you installed a beta version of savespss from this site and not from SSC earlier, uninstall the beta version and reinstall from SSC.

Syntax

The main syntax is trivial:

savespss
will show information about the program and ask for filename to export the current data from memory.
savespss "datafile.sav"
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.

In the current 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:

db savespsssome

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.

Tutorial


Here is an example tutorial for the auto.dta-->auto.sav.

Poll

The poll is now closed.

The data collected with the poll provided evidence that the majority of the users working with SPSS files (50%) are using the most recent version of SPSS, with 11% using the pre-last version. 25% of the users are somewhere between v15.0 and 19.0. No user reported using SPSS prior to v14.0.

Author and support

In case you are experiencing a problem exporting a dataset, and you think the error is mine, kindly let me know.

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)