參考:stata批量讀入excel文件,並合並為一個dta文件
cd "E:\賬面市值比(2000-2020)"
local files: dir . files "*.xls"
foreach file of local files {
import excel using `"`file'"',clear firstrow
local filenm = subinstr(`"`file'"', ".xls", ".dta", .)
save `"`filenm'"', replace
}
clear
local files: dir "." files "*.dta"
foreach file in `files'{
append using `files'
}
save $dircv\MB.dta
subinstr(s1,s2,s3,n)
Description: s1, where the first n occurrences in s1 of s2 have been replaced with s3
If n is missing, all occurrences are replaced.
subinstr("this is the day","is","X",1) = "thX is the day"
subinstr("this is the hour","is","X",2) = "thX X the hour"
subinstr("this is this","is","X",.) = "thX X thX"
Domain s1: strings (to be substituted into)
Domain s2: strings (to be substituted from)【舊】
Domain s3: strings (to be substituted with)【新】
Domain n: integers > 0 or missing
Range: strings