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.
Related Posts with Writing nested foreach loop to convert many .txt files to .dta
Take the latest observation per fiscal-periodHi, I want to take (or mark) the latest forecast (variable= forecast_date) per fiscal-period (varia…
Variable Significance Changes After Adding Regional DummiesDear All, I have two simple yet complicated question. I run my regressions on survey data using th…
Difference-in-difference with three time periodsDear all, I am trying to estimate the difference of impact of the Athenes Olympic and the Paralympi…
Firm FE and firm registration type FEDear friends, I would like to analyze the effect of a policy on the number of patents using the Dif…
Performing operations by values of a specific unit, by yearHi All, I have data that resembles the following: Code: * Example generated by -dataex-. To ins…
Subscribe to:
Post Comments (Atom)
0 Response to Writing nested foreach loop to convert many .txt files to .dta
Post a Comment