Announcement

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

  • Run a program with a vector of arguments

    Hello everyone,

    I'm running a program including regression with as arguments the outcome (=`1') and a group of covariates (=`2'), as the following example :


    *******************
    capture program drop myreg
    program define myreg

    xi: reg `1' elec `2'

    end

    myreg wwork `something to put here'

    *******************

    So the thing is that my group of covariates is big and varies across groups, so I would like to be able to have only a `2' that will include all of them.
    The question is : what do I have to write in `something to put here' to achieve this ?

    I tried two things that don't work :
    1/ create of vector X = (covariate1, covariate2.....) and then write : myreg wwork X

    but when creating X = (...) it doesn't work (because those covariate1 covariate2.... are variables?).

    2/ Simply write myreg wwork covariate1 covariate2 covariate3 ..... covariateN, believing that Stata may include all the "extra" arguments into the last one (supposed to be the `2').

    I guess it's a basic command in Stata but I didn't find clear documentation for it.

    Is anyone who can help ?

    Thanks.




  • #2
    Update : it works when one writes the group of arguments as a string when running the program. Like this :


    *******************
    capture program drop myreg
    program define myreg

    xi: reg `1' elec `2'

    end

    myreg wwork "covariate1 covariate2 covariate3.... covariateN"

    *******************

    Stata then groups all this covariates to consider them as `2'.

    Comment


    • #3
      You can add a simple check so you will not accidentally forget the double quotes:

      Code:
      program define myreg
          args depvar indepvars void
          if (`"`void'"' != "") error 198
          regress `depvar' elec `indepvars'
      end
      Note that the code is more readable this way, too. Note also that I have omitted the obsolete xi prefix. The xi prefix can mess things up for postestimation commands, so it is better avoided. Factor variable notation (see help fvvarlist) is used in its place in modern versions of Stata.

      Best
      Daniel

      Comment

      Working...
      X