I have a feeling I must be making a basic error here, but each time I try to use preserve and restore, I get the error "nothing to restore" r(622), for which the manual says:
This code reproduces the problem:
What am I doing wrong, please? The following does work, so is the problem something to do with my generating data from scratch?
I'm using Stata/BE 18.0 for Mac (Intel 64-bit), revision 04 Sep 2024. MacOS version is 14.6.1, Intel i5. Thank you.
"error . . . . . . . . . . . . . . . . . . . . . . . . Return code 622
nothing to restore
You issued the restore command, but you have not previously specified
preserve."
nothing to restore
You issued the restore command, but you have not previously specified
preserve."
drop _all
set obs 30
gen x = rbinomial(1, 0.5)
gen y = rnormal() + x
list
preserve
collapse y, by(x)
list
restore
set obs 30
gen x = rbinomial(1, 0.5)
gen y = rnormal() + x
list
preserve
collapse y, by(x)
list
restore
webuse college
preserve
list in 1/10
collapse (mean) gpa, by(year)
list
restore
preserve
list in 1/10
collapse (mean) gpa, by(year)
list
restore
Comment