从Excel文件检索数据的Stata循环
我的Excel文件有许多工作表。我试图创建一个循环来检索每一页数据,以便将其保存为.dta。这是我的代码:从Excel文件检索数据的Stata循环,excel,loops,stata,stata-macros,readstata13,Excel,Loops,Stata,Stata Macros,Readstata13,我的Excel文件有许多工作表。我试图创建一个循环来检索每一页数据,以便将其保存为.dta。这是我的代码: local sheet = `" "Data dictionary" "Wave 1" "Wave 2" "Wave 3" "Wave 4" "' foreach x of local sheets{ import excel "/Users/a/D
local sheet = `" "Data dictionary" "Wave 1" "Wave 2" "Wave 3" "Wave 4" "'
foreach x of local sheets{
import excel "/Users/a/Downloads/EVSdata.xlsx", sheet("`x'")
save "/Users/a/Downloads/sheet_`x’.dta"
}
输出没有显示任何错误,但也没有保存数据。这是一个很好的尝试,但代码中有一些小的语法错误。请注意此代码中的细微差异:
local sheet = `" "Data dictionary" "Wave 1" "Wave 2" "Wave 3" "Wave 4" "'
foreach x in `sheet' {
import excel "mydata.xlsx", sheet("`x'") clear
save "sheet_`x'.dta", replace
}
这是一个很好的尝试,但是代码中有一些小的语法错误。请注意此代码中的细微差异:
local sheet = `" "Data dictionary" "Wave 1" "Wave 2" "Wave 3" "Wave 4" "'
foreach x in `sheet' {
import excel "mydata.xlsx", sheet("`x'") clear
save "sheet_`x'.dta", replace
}