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 August 2007
|
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 yet upgraded to the latest release. For
example, when a Stata 7 user tries to open a Stata 8 dataset from a
colleague, they are presented with an error,
. use auto.dta
file auto.dta not Stata format
r(610);
There is, however, an easy solution to this problem. Since Stata 4,
StataCorp has provided a way to save your dataset so that it can be read by
the previous version of Stata. That is, you can save Stata 10 datasets so
that 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 that they
can be read by Stata 7, Stata 7 datasets can be saved so that 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 Stata 10 datasets so they can be read by Stata 8 or Stata 9
To save a Stata 10 dataset so that it can be used in Stata 8 or Stata 9,
use the
saveold command.
. saveold auto10
file auto10.dta saved
Saving Stata 9 datasets so they can be read by Stata 8
Stata 8 and Stata 9 datasets have the same format. Therefore, a Stata 9
dataset 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 Stata 8 or Stata 9 datasets so they can be read by Stata 7
To save a Stata 8 or Stata 9 dataset so that it can be used in Stata 7,
use the
saveold command.
. saveold auto7
file auto7.dta saved
Saving datasets from Stata versions 4 to 7 so they can be read by the previous
version
To save a Stata 4, 5, 6, or 7 dataset 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
Please note that 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 a large number of 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
|