Hi all,
I'm using Stata 15 and trying to import and append a bunch of txt files. I obtain a list of txt files using the user written command -filelist-, these are saved in memory. I then try and loop through the list but my loop fails because I have dropped the original list from memory. How can I loop through all of the txt files and append?
This is what code I have so far:
I'm using Stata 15 and trying to import and append a bunch of txt files. I obtain a list of txt files using the user written command -filelist-, these are saved in memory. I then try and loop through the list but my loop fails because I have dropped the original list from memory. How can I loop through all of the txt files and append?
This is what code I have so far:
Code:
filelist
keep if strpos(filename, "Observation") & regexm(filename, "[\.txt]")
local obs = _N
save "myfilelist.dta", replace
forvalues i = 1/`obs' {
local f = filename[`i']
import delimited "`f'", clear
append using "`f'"
}

Comment