Sep 27, 2015

Appending all files in a directory

cd "E:\eu-lfs\converted files"

local filelist : dir . files "*_y.dta"  // Create local wit all filenames ending with "_y.dta
di `filelist'

local first : word 1 of `filelist'      // Identify first file
di "`first'"

local total_ : word count `filelist' // Identify total number of files
di `total_'

use "`first'", clear                    

forvalues x = 2/`total_' {
    di `x'
    local y : word `x' of `filelist'
    append using "`y'", force
}

save eulfs, replace