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
Triple Difference vs Difference in Differences?Hi, I'm trying to figure out the right way to implement an estimator. Some notes: I'm using an in…
Convergence not Achieved in Mixed ModelHi, I am trying to fit a crossed-effects mixed model in my data but Stata returns the following err…
Margins postestimation command after xtabond2Hi Statalisters, I ran xtabond2 command to study the dynamic relationship between institutions and …
Fixed Effectsdear Statalists, I discovered recently that an independent variable, which I was using in a fixed e…
Change yscale on twoway plotHi, I would like to plot the following graph between [2.5 ; 3]: Code: * Example generated by -dat…
Subscribe to:
Post Comments (Atom)
0 Response to Writing nested foreach loop to convert many .txt files to .dta
Post a Comment