Announcement

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

  • Defining programs within programs, the -runby- command, and passing functions with arguments

    I am trying to pass a function through -runby-, this action is part of a larger loop in which the function in question changes at every iteration. If I am reading the documentation correctly, this is currently not possible with -runby-.

    Current workout (faulty):
    Let `programA(inputA)` be the program of interest. Although we can't pass `inputA` through `programA` through -runby-, we still want to leverage runby's speed so we decide to write a program called `programA_Wrapper` that creates a function called `programA_inputA`, which is then passed through -runby- as follows:

    Code:
    runby programA_inputA, by(state) verbose
    `programA_Wrapper` takes `inputA` as an argument through the standard `syntax` command.

    Issue with the proposed workaround:
    I am getting an error that `programA_inputA` is not being recognized which makes me think that STATA programs can't write other programs, is that correct? Is there an alternative?

    PS. I am unfamiliar with the formatting language in this forum. In standard markdown we wrap inline code with (` `), what is the equivalent here?
    Last edited by Hong-Yi Tu Ye; 17 Mar 2018, 16:48.

  • #2
    Minor point, you pass the name of a user-written Stata program (not a function) to runby, which will then call that program once for each by-group data subset. I think that I addressed the issue in this previous thread. If not, please post an example with representative dataset(s) and the code you got so far.

    Comment


    • #3
      Thanks, your global macro suggestion from the other thread was exactly what I was looking for.

      Comment

      Working...
      X