Dear Statalist users,
I am trying to append close to a million csv files in Stata using the following code:
In principle, this code works fine as long as I am using a small number of files. However, once I apply it to the full dataset, I get the error "cannot compute" for the command:
I am not sure if this is because Stata is running out of memory due to the large number of strings (i.e., file directories) it is storing, or if this is some other problem. In any case, is there another workaround for appending many files?
Best regards,
Marvin
I am trying to append close to a million csv files in Stata using the following code:
Code:
clear all
filelist, dir("I:\MyData") pattern("*.csv")
gen dirname_fixed = subinstr(dirname, "/", "\", .)
drop dirname
gen filepath = dirname_fixed + "\" + filename
levelsof filepath, local(csv_files)
tempfile building
qui save `building', emptyok
foreach f of local csv_files {
import delimited using `"`f'"', bindquote(strict) maxquotedrows(1000) varnames(1) delimiters(",") clear
gen file = `"`file'"'
append using `building'
save `"`building'"', replace
}
Code:
levelsof filepath, local(csv_files)
Best regards,
Marvin

Comment