Reputation: 29
I have a folder called Workdata. In this folder I have the following files.
- Mydata_biology
- Mydata_chemisty
- Mydata_math
- uncleandata_1
- uncleandata_2
If I wanted to append all the files in this folder I can use the following code :
local allfiles : dir "Data\scores" files "*"
foreach f in local allfiles {
*append loop
}
However when i try to append only the first 3 that start with Mydata I can no longer use local allfiles
I tried the following code, but it did not work:
local allfiles : dir "Data\scores" files "Mydata*"
foreach f in local allfiles {
*append loop
}
Upvotes: 1
Views: 6934
Reputation: 11102
The foreach loop is not correctly setup. You want
foreach f of local ...
and you have
foreach f in local ...
There's a difference, and it's important. Check help foreach
, if needed.
Upvotes: 1
Reputation: 9460
I don't think you need a loop. This is pretty easy with user-written fs
:
cd "Data/scores"
ssc install fs
fs "Mydata*.dta"
append using `r(files)'
Upvotes: 1