I have data of banks by id numbers. What I want to do is: (1) to merge 4 tables of one bank, then (2) to repeat the merging for another 29 banks, then (3) to append 30 banks into one file. Please help me with a loop for this task.
The repetitive codes are as follows.
Code:
*bank 1 (id 25046) use 25046_0119_tab1.dta, clear merge 1:1 bankid using 25046_0119_tab2.dta drop _merge merge 1:1 bankid using 25046_0119_tab3.dta drop _merge merge 1:1 bankid using 25046_0119_tab4.dta drop _merge save 25046_0119.dta, replace *bank 2 (id 25047) use 25047_0119_tab1.dta, clear merge 1:1 bankid using 25047_0119_tab2.dta drop _merge merge 1:1 bankid using 25047_0119_tab3.dta drop _merge merge 1:1 bankid using 25047_0119_tab4.dta drop _merge save 25047_0119.dta, replace *repeat for bank 3 id 25048 until bank 30 *and then append 25046_0119.dta using 25047_0119.dta 25048_0119.dta and so on
Lynn
0 Response to looping over data files
Post a Comment