Hi!

I am wondering how to run a macro-command on multiple files in a folder. The file-names (txt) are consecutively numbered but also have different names: chunkcontactinfo0001, chunkcontactinfo0002, chunkcontactinfo0003, chunkcontactinfo0004......; chunkidentifiers0001, chunkidentifiers0002, chunkidentifiers0003, chunkidentifiers0004. In total, there are around 1000 txt-files which are are all around 2GB in size.

I am first extracting and merging data from certain columns of a txt-file, after which this data is matched using an identifier (bvdidnumber).
*2b. Extract data from contact info_MACRO VERSION*

loc c 0
foreach col in 1:2 12:13 15:16 {
loc ++c
import delimited using "D:\js\chunkcontactinfo0001.txt", clear delimiter(tab) varnames(1) bindquote(nobind) encoding(UTF-8) colrange(`col')
save temp`c', replace
}
use temp1, clear
forvalues d=2/`c' {
merge 1:1 _n using temp`d', nogen
}
compress
save contactinfo1, replace

*3. Merge relevant contact info*
use bvdid1
merge 1:1 bvdidnumber using contactinfo1, keep(1 3) nogen
save contactinfofinal0001, replace

How would I get this process to repeat for all the files? And would I need to go through each category separately e.g. chunkcontactinfo0001 - chunkcontactinfo0040, then chunkidentifiers0001 - chunkidentifiers0040 etc.?