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)
Removing specific observationsHello everyone, Based on my title post it seems the question is repeated but no it’s different. my q…
Problems of setting intial values in semDear all, I am running a sem on the following data. My command is sem trust->std_retweet std_fav…
I use qreg, then margins, then mplotoffset: how do I change the spacing for my y-axis?Hi Stata community, I want to change the spacing for my y-axis. Currently I have 0.5 cm between one…
I need to transpose every row of data, not including the first column, into each corresponding value of the first column.Here is an example of my data: Code: * Example generated by -dataex-. To install: ssc install data…
Probit QuestionHi all, If I have a panel of people from ages 25-30, who I may observe more than once in these ages…
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