1

I'm trying to run a regression with a bunch of interactions. Specifically, I have a macro and one interaction variable, but want the interaction variable to interact with everything in the macro.

So far, what I have looks like

local example "covariate1 covariate2"

reg outcome_var `example' `example'#interaction_var

The problem is that

`example'#interaction_var

only has interaction_var interacting with one of the covariates in example, but I want all the covariates interacted with. Is there a way to have an interaction term for every covariate in the macro?

EDIT: I've decided to go an alternate route, since a one-liner may not be possible. Namely, I'm trying to loop over the macro, where for each word in the macro, I interact it with the interaction variable and append it to a new, blank macro. So right now, this looks like

local ints ""
local len_e : word count $example
forval i=1/len_e{
    local e `:word `i' of `example''
    local ints $ints `e'#`int'
}

but I'm getting an invalid syntax error.

  • You're confusing globals and locals, What is in `global example`? What is in `local int`? What is `len_p`? These may be defined previously, but they aren't shown in your thread. – Nick Cox Feb 09 '22 at 16:02
  • Sorry, `len_p` should have been `len_e`. I'm only using locals here, and `local int` is supposed to be a blank macro at first, before I append it with interactions of the form ``e'#`int'`. – MambaMentality Feb 09 '22 at 16:19

1 Answers1

2

The thing to do is to add parentheses around the macro, i.e.

reg outcome_var `example' (`example')#interaction_var

Then interaction_var interacts with everything inside example.