Hello,
I am trying to obtain a list of files matching a wildcard expression and append them all together. The list of files is long, so I would like to use a loop.
I have figured out two ways of getting macro with a list of files:
The first produces a local named filelist and the second produces a local r(files). I can print the entire list using --di ""`filelist'""--
I can print the list of files one by one successfully:
However, I cannot use --append--, and I tried using quotes and no quotes around `file':
What am I doing wrong? I suspect that the first entry in `filelist' is actually an empty string, but I don't know how to get rid of this. For now I have found a workaround using
inside the loop, but this seems rather inelegant.
I am trying to obtain a list of files matching a wildcard expression and append them all together. The list of files is long, so I would like to use a loop.
I have figured out two ways of getting macro with a list of files:
Code:
local filelist: dir dirname files "*pattern*.dta" //1 ssc install fs fs dirname/*pattern*.dta //2
I can print the list of files one by one successfully:
Code:
.foreach file in ""`filelist'"" { 2. di "`file'" 3. } file1.dta file2.dta file3.dta }
Code:
. clear . foreach file in ""`filelist'"" { 2. append using ""`file'"" 3. } file not found r(601); . foreach file in ""`filelist'"" { 2. append using `file' 3. } invalid file specification r(198);
Code:
if "`file'" != "" { append using "`file'" }
Comment