2012-02-02 20 views
1

我想將noconstant選項從包裝程序傳遞到內部regress調用。下面的解決方案有效,但是如果我想通過幾個選項,它看起來特別的煩躁和不可擴展。如何將`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 

回答

3

第二不起作用,因爲當地的宏最終被稱爲constant,不noconstant,截至help syntax##optionally_off描述。

regress `y' `x', `noconstant' 

是::所以,如果你更換應該工作

regress `y' `x', `constant' 

如果你想通過幾個選項,它更容易使用*語法在help syntax##description_of_options解釋說:

如果您還指定 *,則收集所有剩餘的選項,並依次放入 `選項'中。

例如爲:

 syntax varlist(min=2 numeric) [if] [in] /// 
      [, *] 
     ... 
     regress `y' `x', `options' 
相關問題