批量将同一文件夹的excel转为dta

参考: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

list.png

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
posted @ 2021-10-09 17:17  将军练码  阅读(1517)  评论(0)    收藏  举报