Hello,

I have encountered a strange problem (at least for me). I run a loop of the following form to generate a distribution of adjusted R2s (can't use the bootstrap command for reasons irrelevant here):

clear
save "XY", replace emptyok

forvalues i = 1/1000 {
display `i'
use "XYZ" , clear
bsample 1000
quietly: reg xy
clear
save "helpfile", replace emptyok
set obs 1
gen ar2_xy =.
replace ar2_xy = e(r2_a)
save "helpfile", replace
use "XY", clear
append using "helpfile"
save "XY", replace
}


The code works in principle and sometimes runs through smoothly, but most times after a random number of iterations gives me:

(...)
109
(note: dataset contains 0 observations)
file helpfile.dta saved
number of observations (_N) was 0, now 1
(1 missing value generated)
(1 real change made)
file helpfile.dta saved
file XY.dta saved
110
(note: dataset contains 0 observations)
file helpfile.dta cannot be modified or erased; likely cause is read-only
directory or file
r(608);

end of do-file


Why would the file suddenly be read-only? And as I said, sometimes it does finish all 1000 iterations without error.

Thanks a lot for your help!

Ferdinand