如何从以相同字母开头的相同目录和文件夹中追加 Stata 中的文件?
How to append files in Stata from the same dir and folder that start with the same letter?
我有一个名为 Workdata 的文件夹。在这个文件夹中,我有以下文件。
- Mydata_biology
- Mydata_chemisty
- Mydata_math
- uncleandata_1
- uncleandata_2
如果我想附加此文件夹中的所有文件,我可以使用以下代码:
local allfiles : dir "Data\scores" files "*"
foreach f in local allfiles {
*append loop
}
但是,当我尝试仅附加以 Mydata 开头的前 3 个文件时,我无法再使用本地所有文件
我尝试了以下代码,但没有成功:
local allfiles : dir "Data\scores" files "Mydata*"
foreach f in local allfiles {
*append loop
}
我认为您不需要循环。使用用户编写的 fs
:
非常容易
cd "Data/scores"
ssc install fs
fs "Mydata*.dta"
append using `r(files)'
foreach 循环设置不正确。你想要
foreach f of local ...
你有
foreach f in local ...
有区别,而且很重要。如果需要,勾选 help foreach
。
我有一个名为 Workdata 的文件夹。在这个文件夹中,我有以下文件。
- Mydata_biology
- Mydata_chemisty
- Mydata_math
- uncleandata_1
- uncleandata_2
如果我想附加此文件夹中的所有文件,我可以使用以下代码:
local allfiles : dir "Data\scores" files "*"
foreach f in local allfiles {
*append loop
}
但是,当我尝试仅附加以 Mydata 开头的前 3 个文件时,我无法再使用本地所有文件
我尝试了以下代码,但没有成功:
local allfiles : dir "Data\scores" files "Mydata*"
foreach f in local allfiles {
*append loop
}
我认为您不需要循环。使用用户编写的 fs
:
cd "Data/scores"
ssc install fs
fs "Mydata*.dta"
append using `r(files)'
foreach 循环设置不正确。你想要
foreach f of local ...
你有
foreach f in local ...
有区别,而且很重要。如果需要,勾选 help foreach
。