Announcement

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

  • How to graph the interaction effects of two dummy variables?

    Hi,
    I am trying to graph an interaction between two dummy variables (s and p) to see if the interaction is a good predictor for my outcome variable (o)?

    I THINK my command to find the interaction is : regress o s#p
    Right??

    But then I don't know what command to use to find the graph. I've browsed this forum before so I've seen that there are multiple types of interactions but I'm not entirely sure which one I am looking for either.

    Thank you in advance!!

  • #2
    Farwah:
    welcome to this forum.
    Usually, the regression model should also include the so called main conditional effect of the predictors included in the interaction.
    In you case, I would change your code a bit:
    Code:
    regress o i.s##i.p
    If you're interested in plotting the interaction, you should consider:
    Code:
    margins i.s#i.p
    marginsplot
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Hi,

      Thanks for the response! When I used the regression model code you provided, it gave me the same results that I had from the one I initally used so I'm a little confused on that. Also, the command for the graph unfortunately did not give the graph I need. I am looking at the interaction of s#p as a predictor of o, which is also a dummy variable, so I am trying to find a graph command for this.

      Comment


      • #4
        Farwah:
        no wonder that our code give back the same graph, as they are absolutely the same.
        My warning concerning main conditional effect was about your regression code at large.
        You can see from the regression outcome table (looking at 95% CI) whether or not interaction is a "good" predictor for the regressand.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          If o is dichotomous you probably want to use logistic regression. Disregarding that, here is a silly regression model but it shows what Carlo suggested you do, and it shows exactly the interaction that you indicated you are interested in.


          Code:
          . sysuse auto
          (1978 Automobile Data)
          
          . gen lompg = mpg < 20
          
          . reg price i.for#i.lo
          
                Source |       SS           df       MS      Number of obs   =        74
          -------------+----------------------------------   F(3, 70)        =      3.98
                 Model |  92587422.9         3  30862474.3   Prob > F        =    0.0112
              Residual |   542477973        70  7749685.33   R-squared       =    0.1458
          -------------+----------------------------------   Adj R-squared   =    0.1092
                 Total |   635065396        73  8699525.97   Root MSE        =    2783.8
          
          -------------------------------------------------------------------------------
                  price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
          --------------+----------------------------------------------------------------
          foreign#lompg |
            Domestic#1  |   1722.012    781.397     2.20   0.031     163.5649    3280.459
             Foreign#0  |   460.4572   898.9562     0.51   0.610    -1332.454    2253.369
             Foreign#1  |   4179.645   1379.201     3.03   0.003     1428.916    6930.375
                        |
                  _cons |   5078.955   593.5136     8.56   0.000     3895.229     6262.68
          -------------------------------------------------------------------------------
          
          . margins for#lo
          
          Adjusted predictions                            Number of obs     =         74
          Model VCE    : OLS
          
          Expression   : Linear prediction, predict()
          
          -------------------------------------------------------------------------------
                        |            Delta-method
                        |     Margin   Std. Err.      t    P>|t|     [95% Conf. Interval]
          --------------+----------------------------------------------------------------
          foreign#lompg |
            Domestic#0  |   5078.955   593.5136     8.56   0.000     3895.229     6262.68
            Domestic#1  |   6800.967   508.2547    13.38   0.000     5787.285    7814.649
             Foreign#0  |   5539.412   675.1769     8.20   0.000     4192.814     6886.01
             Foreign#1  |     9258.6   1244.965     7.44   0.000     6775.596     11741.6
          -------------------------------------------------------------------------------
          
          . marginsplot
          Click image for larger version

Name:	marginsdemo.png
Views:	1
Size:	23.3 KB
ID:	1503780
          Richard T. Campbell
          Emeritus Professor of Biostatistics and Sociology
          University of Illinois at Chicago

          Comment

          Working...
          X