1

noconstantラッパー プログラムから内部regress呼び出しにオプションを渡したいと思います。次の解決策は機能しますが、いくつかのオプションを渡したい場合は、特にぎこちなく、拡張できないようです。

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
4

1 に答える 1

3

で説明されているように、ローカル マクロはconstantではなくで呼び出されるため、2 番目のマクロは機能しません。したがって、次のように置き換えれば機能するはずです。 noconstanthelp syntax##optionally_off

   regress `y' `x', `noconstant'

に:

   regress `y' `x', `constant'

複数のオプションを渡したい場合は、 で*説明されている構文を使用する方が簡単help syntax##description_of_optionsです。

* も指定すると、残りのオプションがすべて収集され、`options' に次々に配置されます。

例えば:

       syntax varlist(min=2 numeric) [if] [in] ///
            [, *]
       ...
       regress `y' `x', `options'
于 2012-02-02T16:25:45.610 に答える