STATA为什么返回未知功能+ inrange()”?
我正在研究Stata编程的书籍 STATA编程简介,第二版。
在第4章中,有代码生成
一个测试其他一些变量是否满足逻辑条件的变量,代码就像:
foreach v of varlist child1-child12{
local n_school "`n_school' + inrange(`v', 1, 5)"
}
gen n_school = `n_school'
当我更改此代码以适合自己的数据时,
foreach v of varlist qp605_s_1-qp605_s_5 {
local n_med "`n_med' + inrange(`v', 1, 5)"
}
gen n_med = `n_med'
其中qp605_s_1 < /code>的值范围从1到17,然后stata返回:
. foreach v of varlist qp605_s_1-qp605_s_5 {
2. local n_med "`n_med' + inrange(`v', 1, 5)"
3. }
. gen n_med = `n_med'
unknown function +inrange()
r(133);
此代码有什么想法?
I am studying Stata programming with the book An Introduction to Stata Programming, Second Edition.
In chapter 4 there is code to generate
a variable that tests whether some other variables satisfy a logical condition, the code is like:
foreach v of varlist child1-child12{
local n_school "`n_school' + inrange(`v', 1, 5)"
}
gen n_school = `n_school'
When I change this code to suit my own data,
foreach v of varlist qp605_s_1-qp605_s_5 {
local n_med "`n_med' + inrange(`v', 1, 5)"
}
gen n_med = `n_med'
where qp605_s_1
's values range from 1 to 17, then Stata returns:
. foreach v of varlist qp605_s_1-qp605_s_5 {
2. local n_med "`n_med' + inrange(`v', 1, 5)"
3. }
. gen n_med = `n_med'
unknown function +inrange()
r(133);
Any ideas what is wrong with this code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(2)
我看到我在哪里误解了
本地
n_med
以+
开始,因此我将其更改为:它可以使用!
顺便说一句,根据的stata编程简介,此方法比您首先
生成
一个均为零的变量,然后replot> replace>替换
它通过循环,因为替换
命令比生成
要慢,因此最好避免替换
。I see where I was wrong
The local
n_med
begins with+
, so I change it to:and it works!
BTW, according to An Introduction to Stata Programming, this method is faster than if you first
generate
a variable which is all zero and thenreplace
it by a loop, because thereplace
command is slower thangenerate
, so it is better to avoidreplace
.这是另一种方法。
Here is another approach.