Hello,

I am trying to collapse all files in a folder and replace the old files with the new ones. Stata seems to be having trouble with the code to save and replace the collapsed files. Here is what I have written so far:
Code:
local files : dir "E:\Data3" files "*.dta"
 
cd "E:\Data3"

foreach file in `files' {
        use `file’, clear
        collapse (mean) tMin tMax prec, by (dateNum fips_code)
        save, replace
}
Stata returns:
invalid file specification
r(198);
I think the error has something to do with trying to save a file after it has been collapsed. I have tried to collapse just one file, which works, but when I try to save it I get the same error.

Thank you.