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)
Can't find PIPI'm running Spyder Python 3.3.6 from Stata/IC 16.1 for Mac (64-bit Intel): Code: . python query --…
Difference in SE and CI using svyset v. pweight - reason for difference?I am working on analyzing survey data which was collected using a stratified random sample, with dis…
Generate and replace multiple variables based on original variables.Hello Statalist, Hope everyone is doing fine in the middle of this pandemic. I'm working with a da…
See change in composition of traded goods according to Product Complexity IndexDear Statalisters, I want to measure the influence of trade agreements on the composition of the tr…
How can I change the scale of the y-axis in a Barchart Hello, I would be very grateful if someone could help me with the scale of the y-axis of my barcha…
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