stata - 与多个命令一起使用时,捕获不起作用
问题描述
我的文件中有多个3,000
变量和标签do
,但在我的数据集中我需要~300
标签。为了绕过没有变量的错误,我使用了capture
命令。
在我的数据中,没有hhid
orhh_cu_q
变量,只有一个newid
变量:
capture noisily {
label var hhid "Identifier for household with more than one CU. Household with only one CU will be set to missing."
label var hh_cu_q "Count of Consumer Units in this household"
label var newid "Public use microdata identifier"
}
但是,当我运行此代码时,我看到命令第一行的错误(hhid
未找到变量),并且似乎 Stata 正在执行其余的行,但标签没有变化!
如果我只运行命令的最后一行,它工作正常(它添加标签newid
)。
解决方案
这是正常行为,因为您正在应用capture
整个命令块。因此,当出现错误时,Stata 会绕过块中的所有剩余命令并继续执行do
文件的其余部分。
单独应用时capture
,一切都按您的预期工作:
clear
set obs 1
generate newid = .
. capture noisily label var hhid "Identifier for household with more than one CU. Household with only one CU will be set to missing."
variable hhid not found
. capture noisily label var hh_cu_q "Count of Consumer Units in this household"
variable hh_cu_q not found
. capture noisily label var newid "Public use microdata identifier"
. display "`: variable label newid'"
Public use microdata identifier
推荐阅读
- python - 根据特定顺序对字符串和数字列表进行排序
- java - java函数的大o表示法
- awk - gsub:删除直到第一次出现而不是一行中给定字符的最后一次出现
- subdomain - 在子域共享主机上发布 React JS
- java - Siddhi 应用程序 mongo-store 扩展中的 com/mongodb/MongoException
- android - 我如何在 Geckoview Android 中设置通知栏音乐控制小部件
- javascript - 在 CKEditor 4.16 中使用提及
- html - Bootstrop 5 Carousel Prev 按钮有效,next 无效
- javascript - 如何使用jQuery独特地最小化和最大化卡片
- javascript - 函数数组 - 模 - 每隔一个元素加 1