I would like to pass the noconstant option from a wrapper program to an inside regress call. The following solution works, but it seems particularly janky and not extensible if I would like to pass several options.
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)
I thought that something more like the following would work, but it doesn’t pass the noconstant option.
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
The second doesn’t work because the local macro ends up being called
constant, notnoconstant, as described athelp syntax##optionally_off. So it should work if you replace:by:
If you want to pass several options on, it’s easier to use the
*syntax explained athelp syntax##description_of_options:e.g.: