How can I save a Stata dataset so that it can be read by a previous version of
Stata?
|
Title
|
|
Reading a Stata dataset with an older version of Stata
|
|
Author
|
Shannon Driver, StataCorp
|
|
Date
|
August 1999; updated September 2011
|
The format sometimes changes between releases to allow for new features.
This format change can cause problems when two colleagues are working on a
project and one of them has not upgraded to the latest release. For
example, when a Stata 10 user tries to open a Stata 12 dataset from a
colleague, they are presented with an error,
. use auto.dta
file auto.dta from a more recent version of Stata
r(610);
There is, however, an easy solution to this problem. First, Stata 11
can read Stata 12 datasets, and Stata 10 can read Stata 11 datasets.
Also, since Stata 4,
StataCorp has provided a way to save your dataset so it can be read by
the previous version of Stata. That is, you can save Stata 12 datasets so
they can be read by Stata 8 through Stata 10. Stata 11 or
Stata 10 datasets can be saved so
they can be read by Stata 8 or Stata 9 (Stata 8 and Stata 9 share the
same dataset format). Stata 8 or Stata 9 datasets can be saved so they
can be read by Stata 7. Stata 7 datasets can be saved so they can be
read by Stata 6, and so on down to Stata 4 datasets, which can be saved so
that Stata 3.1 can read them.
Saving datasets in Stata 12 so they can be read by Stata 11
Stata 11 can read Stata 12 datasets, so you do not need to do
anything special:
. save auto
file auto.dta saved
Saving datasets in Stata 12 so they can be read by Stata 8, Stata 9,
or Stata 10
To save a dataset in Stata 12 so that it can be used in any of Stata 8
through Stata 10, use the saveold command.
. saveold autoold
file autoold.dta saved
Saving datasets in Stata 10 or Stata 11 so they can be read by
Stata 8 or Stata 9
To save a dataset in Stata 10 or Stata 11 so that it can be used
in Stata 8 or Stata 9,
use the
saveold command.
. saveold autoold
file autoold.dta saved
Saving datasets in Stata 9 so they can be read by Stata 8
Stata 8 and Stata 9 datasets have the same format. Therefore, a dataset
saved in Stata 9 can be used in Stata 8 with no problems or extra work.
The only issue related to this is that Stata 9 allows value labels to be up
to 32,000 characters long. If Stata 8 tries to read a Stata 9 dataset with
value labels that exceed the Stata 8 limit (244 for Stata/SE; 80 for Stata
Intercooled), Stata 8 will ignore those labels and read the rest of the
dataset.
Saving datasets in Stata 8 or Stata 9 so they can be read by Stata 7
To save a dataset in Stata 8 or Stata 9 so that it can be used in Stata 7,
use the
saveold command.
. saveold auto7
file auto7.dta saved
Saving datasets in Stata 4 to Stata 7 so they can be read by the previous
version
To save a dataset in Stata 4, 5, 6, or 7 so that it can be read by the
previous version, use the
save command with the old option.
. save auto6, old
file auto6.dta saved
The old option in Stata 7 will not automatically
truncate long variables or label names. This must be dealt with in one of
two ways. You can either rename the variables and labels by hand or use
Stat/Transfer
to translate the datasets. The second suggestion is
very handy if you have many variables.
Also, if any of your variables have value labels and the name of the value
label is longer than 8 characters, you must either drop or rename those
value labels.
. label list
origin:
0 Domestic
1 Foreign
. label save origin using mylabel.do
file mylabel.do saved
This command will produce a do-file called mylabel.do with the
following commands:
-------------------------------------------------mylabel.do
label define origin 0 `"Domestic"', modify
label define origin 1 `"Foreign"', modify
-------------------------------------------------mylabel.do
|