Stata 如何将'noconstant'或其他选项从包装程序传递到内部的'regresse'调用
我想将Stata 如何将'noconstant'或其他选项从包装程序传递到内部的'regresse'调用,stata,Stata,我想将noconstant选项从包装程序传递到内部回归调用。下面的解决方案是可行的,但如果我想通过几个选项,它似乎特别不方便,而且不可扩展 webuse grunfeld, clear capture program drop regress_wrapper program define regress_wrapper version 11.2 syntax varlist(min=2 numeric) [if] [in] /// [, noconstant(s
noconstant
选项从包装程序传递到内部回归
调用。下面的解决方案是可行的,但如果我想通过几个选项,它似乎特别不方便,而且不可扩展
webuse grunfeld, clear
capture program drop regress_wrapper
program define regress_wrapper
version 11.2
syntax varlist(min=2 numeric) [if] [in] ///
[, noconstant(string)]
tokenize `varlist'
local y `1'
macro shift
local x `*'
regress `y' `x', `noconstant'
end
regress_wrapper invest mvalue kstock
regress_wrapper invest mvalue kstock, noconstant(noconstant)
我原以为下面类似的东西可以工作,但它没有通过noconstant
选项
capture program drop regress_wrapper
program define regress_wrapper
version 11.2
syntax varlist(min=2 numeric) [if] [in] ///
[, noconstant]
tokenize `varlist'
local y `1'
macro shift
local x `*'
regress `y' `x', `noconstant'
end
regress_wrapper invest mvalue kstock
regress_wrapper invest mvalue kstock, noconstant
第二个不起作用,因为本地宏最终被称为
constant
,而不是noconstant
,如中所述。因此,如果您更换:
regress `y' `x', `noconstant'
作者:
regress `y' `x', `constant'
如果要传递多个选项,可以更轻松地使用*
语法,解释如下:
如果您还指定
*,将收集并放置所有剩余选项,一个接一个地放置在中
`选项'
e、 g:
syntax varlist(min=2 numeric) [if] [in] ///
[, *]
...
regress `y' `x', `options'