简体   繁体   English

Stata 循环从 Excel 文件中检索数据

[英]Stata loop to retrieve data from Excel file

My Excel file has many sheets.我的 Excel 文件有很多张。 I am trying to create a loop to retrieve every sheet of data to be able to save it as.dta.我正在尝试创建一个循环来检索每张数据,以便能够将其另存为.dta。 This is my code:这是我的代码:

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"
}

The output does not show any error but it does not save the data either. output 没有显示任何错误,但它也没有保存数据。

A good attempt, but there are a few small syntax errors in your code.一个很好的尝试,但是您的代码中有一些小的语法错误。 Note the subtle differences in this code:请注意此代码中的细微差别:

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM