Announcement

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

  • Plotting interaction with manually created interaction term

    Hello,

    is it possible to plot an interaction using margins / marginsplot if the interaction term was created manually?

    My model looks like this and I am well aware of the possibility to get the interaction terms with the ## notation i.e.:
    Code:
    mixed y c.x1##c.x3 c.x1##c.x4 c.x2##c.x3 c.x2##c.x4  || cntry: x1 x2, cov(uns) || cntryr: x1 x2, cov(uns) var base
    Using this code, I get the desired results using margins / marginsplot. However, since I want to try a proposed technique, I am forced to create the interaction terms by hand.
    I get basically identical results to the model before, but when doing it this way, the margins command after running the model doesn't seem to "get" the interaction..

    Code:
    foreach var of varlist x1 x2{
    egen `var'_dm = mean(`var'), by (cntry)
    replace `var'_dm = `var'-`var'_dm
    gen `var'_gw = `var'_dm*x3
    sum `var'_gw
    replace `var'_gw = `var'_gw-r(mean)
    }
    
    mixed y x3 x1_gw x2_gw c.x1##c.x4 c.x2##c.x4  || cntry: x1 x2, cov(uns) || cntryr: x1 x2, cov(uns) var base
    Is there a possibility to plot the interaction effect?

  • #2
    Use the -expression()- option of margins. But you will have to work out the expression involving the manual interaction term beforehand.

    Comment

    Working...
    X