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.?
Related Posts with How to run the same macro-command(s) on multiple files (creating a loop)
Stata ignores else condition in if-else blocks within forval loopHey everyone, I have three files named something like File_1, File_2, File_3, which I am importing …
creating a loop for multiple regressionsDear Statalist, I am a beginner in Stata and panel data, therefore please excuse me beforehand if m…
Euler's Number in StataHello, I am trying to define a program with: program define MC_3, rclass version 15 clear drop _all…
Merging certain variables whilst matching ID numberDear Statalist, Hope you're well. I am trying to merge certain variables from my using dataset into…
using nlcom to calculate combinations of parameter estimates from different modelsDear Stata users, I am estimating two mixed logit models: (1) mixlogit choice price1, group(idgrou…
Subscribe to:
Post Comments (Atom)
0 Response to How to run the same macro-command(s) on multiple files (creating a loop)
Post a Comment