Hi,

I am trying to include the name of the file as a variable before appending. Please see code below, which works well.

ideally the variable should be created after importing the delimited file, but before saving as a dta file for all files to be appended

Thanks


clear
cd "C:\Users\aaaa"

local files: dir "C:\Users\aaaa" files "*.txt"
foreach file in `files' {
clear
import delimited `file'
save `file'.dta, replace
}



local files: dir "C:\Users\aaaa " files "*.dta"

foreach file in `files' {
append using `file'
}