Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loop to merge multiple dta files

    Hi all,

    I am trying to run a loop to merge 10 files names year_1, year_2, ...., year_10 all at once.
    Each dataset has 4 variables - ID, grades, total_score, time (denoting year number 1, 2, ....,10). Variable ID is same for all datasets.

    I am using

    Code:
     local myfilelist : dir . files "*.dta"
    use year_1  
    foreach f of local myfilelist {
    merge 1:1 ID using `f'
    drop _merge
    save merged, replace }
    However, it is not working. There are no errors. The output data "merged" is same as year_1. What could be going wrong? Any help is much appreciated. Thank you.
    Last edited by Lars Pete; 30 Nov 2021, 18:59.

  • #2
    I think what you need is -append- rather than -merge-.

    Comment


    • #3
      You're right. Thank you.

      Comment

      Working...
      X