Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • macro as program argument

    Good morning everyone,

    I have an issue concerning a program which goal is to run an OLS. I name that program "OLS". I have several arguments in that program, including one name "covariates". When calling program "OLS", I would like to give as "covariates", a local macro called X, containing a list of variables. It does not work. Only the first covariate of the list in the macro is used. And it is clearly the problem: once I change "covariates" in the call by "var1 var2 etc...", i.e without using the local macro X, it works (everything is used). Someone could help me ? I doubt that it is impossible to do such a thing. Thank you in advance. Code below.

    ###
    capture program drop OLS
    program OLS
    args model_name sample treatment group outcome covariates reweight
    eststo `model_name': quietly regress `outcome' `treatment' `covariates' if (`sample'==1 & `group'==1) [aw=weight*`reweight'], vce(robust)
    end
    ###


    ###Call1###
    local X "var1 var2 var3"
    OLS model_name sample treatment group outcome `X' reweight
    ###
    --> Only takes var1 in X

    But here :

    ###Call1###
    OLS model_name sample treatment group outcome "var1 var2 var3" reweight
    ###
    It takes everything of course.





  • #2
    When you use the local macro OLS sees as arguments


    Code:
     model_name sample treatment group outcome X1 X2 X3 reweight
    and X1 is mapped to covariates (it's the 6th argument).

    Your second example implies that you should try


    Code:
    OLS model_name sample treatment group outcome "`X'" reweight

    and then the " " will bind the covariate names into a single argument.

    Comment


    • #3
      Thank you very much for this, it indeed works. I should have searched a little bit more!

      Comment

      Working...
      X