问题
I have a do
-file that i use to clean-up a Stata dataset and generate descriptive statistics. The first command in this file is preserve
, while the last one is restore
.
The do
-file is too long to attach on here but between these two commands, there are others such as generate
, replace
, tabulate
and collapse
.
The problem is that sometimes i get the following error message:
nothing to restore
Does anyone know what might be wrong?
回答1:
The problem presents itself when you are trying to run certain lines of code in
your do
file in chunks, as opposed to running the entire do
file in one go.
To illustrate that this is indeed the case, consider the following toy example:
sysuse auto, clear
preserve
keep price mpg weight foreign
regress price mpg weight foreign
restore
If you select the first three lines from the above code snippet and press "Execute"
in the do
-file editor, Stata will successfully carry these out and then will
automatically restore the dataset.
(To see this, just comment out preserve
in the above example. In this case, the dataset upon completion of running the selected code will only contain the four variables specified.)
Now, if you try to run the rest of the code, Stata will complain:
. restore
nothing to restore
r(622);
The reason for this is because Stata has already restored the dataset.
来源:https://stackoverflow.com/questions/50881707/nothing-to-restore-error