批量將同一文件夾的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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM