我的3,000
文件中有超过do
个变量和标签,但是在我的数据集中,我需要~300
个标签。为了绕过没有变量的错误,我使用了capture
命令。
在我的数据中,没有hhid
或hh_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
添加标签)。
答案 0 :(得分:3)
这是正常现象,因为您在整个命令的整个 block 中都应用了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