多次保存数据
Preserving data more than once
我正在用 Stata 写一些代码,我已经用过 preserve
一次。但是,现在我想再次 preserve
,而不使用 restore
。
我知道这会给出错误信息,但它会保存到新的保护区吗?
不,保留两次而不在中间恢复只会引发错误:
sysuse auto, clear
preserve
drop mpg
preserve
already preserved
r(621);
但是,您可以使用临时文件执行类似的操作。来自 help macro
:
"...tempfile assigns names to the specified local macro names that may be used as names for temporary files. When the program or do-file concludes, any
datasets created with these assigned names are erased..."
考虑以下玩具示例:
tempfile one two three
sysuse auto, clear
save `one'
drop mpg
save `two'
drop price
save `three'
use `two'
list price in 1/5
+-------+
| price |
|-------|
1. | 4,099 |
2. | 4,749 |
3. | 3,799 |
4. | 4,816 |
5. | 7,827 |
+-------+
use `one'
list mpg in 1/5
+-----+
| mpg |
|-----|
1. | 22 |
2. | 17 |
3. | 22 |
4. | 20 |
5. | 15 |
+-----+
我正在用 Stata 写一些代码,我已经用过 preserve
一次。但是,现在我想再次 preserve
,而不使用 restore
。
我知道这会给出错误信息,但它会保存到新的保护区吗?
不,保留两次而不在中间恢复只会引发错误:
sysuse auto, clear
preserve
drop mpg
preserve
already preserved
r(621);
但是,您可以使用临时文件执行类似的操作。来自 help macro
:
"...tempfile assigns names to the specified local macro names that may be used as names for temporary files. When the program or do-file concludes, any datasets created with these assigned names are erased..."
考虑以下玩具示例:
tempfile one two three
sysuse auto, clear
save `one'
drop mpg
save `two'
drop price
save `three'
use `two'
list price in 1/5
+-------+
| price |
|-------|
1. | 4,099 |
2. | 4,749 |
3. | 3,799 |
4. | 4,816 |
5. | 7,827 |
+-------+
use `one'
list mpg in 1/5
+-----+
| mpg |
|-----|
1. | 22 |
2. | 17 |
3. | 22 |
4. | 20 |
5. | 15 |
+-----+