Let's say I have data on imports to the U.S., commodity by country, on
a yearly
basis (such as Feenstra's TSUSA Imports). The original data are in txt
format
and there are three txt files per year. Assume file names are
completely
random but all the files have identical layout (var names, type, etc.).
Now I want to infile the txt files into Stata, save them in dta format
as
import1, import2, ... , import51...
forvalues i = 1(1)51 {
infile using C:\Imports\import`i'.txt
save import`i'
clear
}
... and then I want to create one huge dataset:
use import1
forvalues i = 2(1)51 {
append using import`i'
}
save import-big
Since all you're going to do is append all these files together, do
that at the operating system level, and read just one file into Stata:
!cat *.txt > allfiles.raw
infile using allfiles.raw
or whatever is the equivalent construction in your OS.
Alternatively, use fs:
fs *dta
foreach f in `r(files)' {
use `f',clear
desc
}