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)
Accessing ado code for svy: total to identify variance estimation methodHello, I'm needing to estimate standard errors in an Excel file, for a complex survey. It is a two s…
Creating graphsHi everyone I have recently started to use Stata, and struggling to create graphs. Which codes shou…
Calculating the difference between two paired observations ignoring missing valuesHi, I'm sure there's a simple way to do this but I can't seem to find a solution. I have two varia…
principal factor vs. principal-component factor option for factor analysis Hello everyone! Can someone explain me the difference between the "principal-factor" and "principa…
(How) Can I calculate a significance test for Kendall´s Tau c in Stata?Dear community, I calculated Kendall´s tau c in Stata "by hand" because the ktau-command only conta…
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