Stata 与多个命令一起使用时,捕获不起作用
我的Stata 与多个命令一起使用时,捕获不起作用,stata,Stata,我的do文件中有3000多个变量和标签,但在我的数据集中,我需要~300个标签。为了绕过没有变量的错误,我使用了capture命令 在我的数据中,没有hhid或hh\u cu\u 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." lab
do
文件中有3000多个变量和标签,但在我的数据集中,我需要~300个标签。为了绕过没有变量的错误,我使用了capture
命令
在我的数据中,没有hhid
或hh\u cu\u 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"
}
但是,当我运行这段代码时,我看到命令的第一行出现了错误(variablehhid
notfound),看起来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
这是正常的行为,因为您正在整个命令块中应用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
谢谢,很好用。在帮助页面中有一部分说我们可以在整个块上应用capture
。不管怎样,我在所有行的前面都添加了捕获。再次感谢!的确“你可以做到,通常这是你想要的,但不是在这里。”帕汉姆感谢你的接受。同样重要的是,用上面的箭头向上投票你看到的所有有用的答案。谢谢,效果很好。在帮助页面中有一部分说我们可以在整个块上应用capture
。不管怎样,我在所有行的前面都添加了捕获。再次感谢!的确“你可以做到,通常这是你想要的,但不是在这里。”帕汉姆感谢你的接受。同样重要的是,用上面的箭头向上投你看到的所有有用的答案。