在Stata中导入第二张Excel文档,而不知道其名称

时间:2015-03-19 15:54:20

标签: for-loop stata

我将一系列excel表附加在一起。对于每个excel doc,我想要第二张。但是,第二张表的名称变化无法预测。

如何告诉Stata导入第二张而不引用其名称?

import excel "test1.xlsx", sheet("xxxx") firstrow clear
save "append.dta", replace

forvalues i = 2/100{
   import excel "test`i'.xlsx", sheet("yyyy") firstrow clear
   append using "append.dta"
   save "append.dta", replace
}

2 个答案:

答案 0 :(得分:4)

使用import excel的describe选项。

import excel using "test.xlsx", describe
import excel using "test.xlsx", sheet("`r(worksheet_2)'") firstrow clear

答案 1 :(得分:1)

导入excel的Stata帮助包括describe选项,并在帮助文件的底部讨论describe选项如何在r()中存储工作表名称。