I just wanted to ask some more experienced fellas if they could see some issues with this code, since erasing any of the datasets would be disasterous!
What I am doing is creating a list of all .dta files in that directory, compressing it, and saving it if, and only if, it actually was compressed.
Code:
clear all
cd "path"
* Get list of all datasets in directory
local files_to_compress : dir . files "*.dta"
* Loop over .dta files in directory
foreach file of local files_to_compress {
* Display current file and load it
di "`file'"
use `file', clear
* Check the size of the file before compression and start compression
local width = c(width)
compress
* If file was compressed, save it, else load next dataset
if (c(width))<`width' save, replace
}
0 Response to Question about scanning through directory and compress all stata files
Post a Comment