如何在Stata中的宏中调用宏
这是我的代码:
local father_yes "c2[_n+`i']==1"
foreach i of numlist 1/15{
replace withfa=1 if "`hz_father_yes'"
}
然后,我发现在我定义的rath_yes宏中无法识别循环的本地宏`i'。我该如何确定它?
Here is my code:
local father_yes "c2[_n+`i']==1"
foreach i of numlist 1/15{
replace withfa=1 if "`hz_father_yes'"
}
Then I found the local macro `i'
of the loop cannot be identified within the father_yes macro I defined. How can I get it identified?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里的主要问题是,当您定义第一个宏时,本地宏尚未定义,因此定义是
在那时并非违法的,而是您想要的。
foreach
在那里是合法的,但是我会重写这一点,因为在您的代码
中,本地宏
authod> auth_yes
如果定义为定义,即使更正不必要的本地宏
hz_father_yes
未定义表单
的比较,如果“
string ” 是非法的,因为字符串不被视为true或true或false。The main problem here is that when you define the first macro, local macro
i
is not defined, so the definition is thenwhich is not illegal at that point, but is not what you want.
foreach
is legal there, but I would rewrite this asnoting that in your code
the local macro
father_yes
would be illegal if used as defined, and even if corrected remains unnecessarythe local macro
hz_father_yes
is not definedcomparisons of the form
if "
string"
are illegal, as strings are not regarded as true or false.我不确定您要做什么,但似乎问题在于您在定义它之前引用
`i''
。除此之外,您可能还会在使用
`HZ_FATHER_YES'
作为字符串中,将其放入字符串引号“”
时,您可能还会遇到错误。这项工作会做:
但是我认为这样做会更干净:
如果这不适合您,请告诉我们您会遇到什么错误。
I am not sure what you are trying to do but it seems as if the issue is that you are referencing
`i'
before you define it.Besides that you are probably also getting errors as you are using
`hz_father_yes'
as a string by putting it inside string quotes""
.Would this work:
But then I think it would be cleaner to do:
Let us know what error you get if this does not work for you.