excel - stata:保存时工作表名称不存在
问题描述
我正在编写一个访问 excel 文件中的多个工作表的 stata 程序,在对它们进行操作之后,我尝试保存结果,但它显示工作表名称不存在(Cabo not found, r(111))我的代码是这样的:
clear
foreach sheet in "Cabo" "Ga" "Inha" {
import excel using "filename.xlsx", sheet("`sheet'") firstrow
//here are operations//
if `sheet' == "Cabo" {
save test1018
}
else {
append using test1018.dta
save test1018
}
}
有谁知道我做错了什么?谢谢!!
解决方案
, replace
在追加后保存数据时,您还需要包含一个for。您还可以通过在循环之前保存一个空数据集来简化代码。然后,每个工作表都将附加到此数据集,您不必将第一个工作表与后续工作表区别对待。
*Save an empty dataset to append to
clear
save test1018.dta, replace emptyok
foreach sheet in "Cabo" "Ga" "Inha" {
import excel using "filename.xlsx", sheet("`sheet'") firstrow
//here are operations//
append using test1018.dta
save test1018.dta, replace
}
推荐阅读
- android - Flutter Firebase Firestore 列表数据保存无法将索引召回为
- javascript - Nodejs,我如何等到上一个帖子请求完成
- firefox-addon-webextensions - 来自内容脚本的跨域请求
- angular - 在 Angular 中随时随地编辑标题(mat-expansion-panel-header)
- python - 使用python过滤每个评级中有n个值的产品
- python - 为什么我的代码没有返回列表 ls 中不大于 t 的 k 个数字的总和?
- flutter - 应用栏内的颤振步进器
- xcode - 如何仅构建指定的目标而不编译对 Xcode 的依赖项
- django - 仅针对一个模板的自定义 500 错误页面
- javascript - 混合错误:此请求已被阻止;内容必须通过 HTTPS 提供