Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Stata错误:变量名无效?_Stata - Fatal编程技术网

Stata错误:变量名无效?

Stata错误:变量名无效?,stata,Stata,我很抱歉,如果这是基本的,但我似乎无法解决这个错误。我正试图在一项调查中排除一些特定的问题 我的代码: qui: ds Q3_9-Q3_11b, has(type numeric) foreach i in `r(varlist)' { qui: tabout `i' using "H:\Electricity1.xls", c(prop ci) f(3) svy append show(none) clab("`i'") } 错误是 问题3.10无效名称 但为什么这是一个无效

我很抱歉,如果这是基本的,但我似乎无法解决这个错误。我正试图在一项调查中排除一些特定的问题

我的代码:

qui: ds Q3_9-Q3_11b, has(type numeric)

foreach i in `r(varlist)'  {
   qui: tabout `i' using "H:\Electricity1.xls", c(prop ci) f(3) svy append show(none) clab("`i'")
   }
错误是

问题3.10无效名称

但为什么这是一个无效的名称


变量名为
Q3\u 10
,标签为
Q3.10

您的示例与捏造的数据一起工作:

clear 
set more off

*----- example data -----

set obs 5

gen Q3_9 = 33
gen Q3_10 = "dog"
gen P4_5 = 56
gen Q3_11b = 24
gen weight = runiform()

svyset weight

qui: ds Q3_9-Q3_11b, has(type numeric)
display "`r(varlist)'"

*----- what you want -----

foreach i in `r(varlist)' { 
    qui: tabout `i' using "H:\Electricity1.xls", ///
        c(prop ci) f(3) svy append show(none) clab("`i'")
}
最好是

foreach i of varlist `r(varlist)' { 
    qui: tabout `i' using "H:\Electricity1.xls", ///
        c(prop ci) f(3) svy append show(none) clab(`i')
}
因为您明确表示列表中包含变量。此外,Stata检查列表中的变量是否存在,以便在进入循环之前捕获任何相关错误

clab()
选项使用引号,但是
帮助文件表明您不需要引号。)


如果您仍然有问题,请在循环之前运行
描述
,并编辑您的问题以包括Stata的输出。

您的捏造数据示例:

clear 
set more off

*----- example data -----

set obs 5

gen Q3_9 = 33
gen Q3_10 = "dog"
gen P4_5 = 56
gen Q3_11b = 24
gen weight = runiform()

svyset weight

qui: ds Q3_9-Q3_11b, has(type numeric)
display "`r(varlist)'"

*----- what you want -----

foreach i in `r(varlist)' { 
    qui: tabout `i' using "H:\Electricity1.xls", ///
        c(prop ci) f(3) svy append show(none) clab("`i'")
}
最好是

foreach i of varlist `r(varlist)' { 
    qui: tabout `i' using "H:\Electricity1.xls", ///
        c(prop ci) f(3) svy append show(none) clab(`i')
}
因为您明确表示列表中包含变量。此外,Stata检查列表中的变量是否存在,以便在进入循环之前捕获任何相关错误

clab()
选项使用引号,但是
帮助文件表明您不需要引号。)


如果仍然存在问题,请在循环之前运行
description
,并编辑您的问题以包括Stata的输出。

在这种情况下,-ds-的输出保证为varlist;这就是命令的要点!因此,这两种语法都很好;这就是命令的要点!所以这两种语法都可以。