I'm trying to write a foreach loop to convert a few hundred text files, divided up into many folders. So far I have this:


foreach f in (listed out folders) {
foreach x in (listed out text files) {
capture import `x' delimited, delimiter(tab)
save `x'.dta, replace
clear
}
}

but I keep getting a "no variables defined" r(111) error. I have a feeling it's about the formatting of the list of folders and files, but I've been struggling to figure out the proper way to do so. I apologize in advance if the code is poorly written. I'm an undergraduate in my first semester of learning Stata.

I didn't want to put the whole lists for the folders and files, because it'd make the post annoying long, but they're listed out in this format:

foreach f in 03312006 03312007 03312008 etc. and
foreach x in CI_03312006.txt ENT_03312006.txt etc.

Thank you.