你是说1800个文件,我看错了,我还以为时1800个数据。
先将1800个文件以一定规律命名统一命名,然后用一个循环将forvalue或foreach将所有csv文件转化成dta文件,命令为insheet using filename.csv,记得保存。然后可以用append命令把所有这些dta文件合并,不过得保证每个文件变量的一致性。
1. rename all the files as "f1.csv", "f2.csv", .."f1800.csv". you can do this in Windows directly, or use some software. say, you save them in the folder "C:\temp"
2. use forvalues:
forv i=1/1800 {
insheet using C:\temp\f`i'.csv
save c:\temp\f`i'.dta, replace
}
3. put all the files into one big file
use c:\temp\f1.dta, clear
forv i=2/1800 {
append using c:\temp\f`i'.dta
}
save c:\temp\all.dta, replace
cd "d:\test\"
local filelist: dir . files "*.csv"
local a 1
foreach x of local filelist {
insheet using `x', tab clear
save file`a'.dta
local a = `a' + 1
}
use file1.dta, clear
local a=`a'-1
forvalue i=2 /`a' {
append using file`i'
}