Announcement

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

  • Plotting an Interaction

    I am trying to plot the effect on Value of an interaction between Trend and Experience, at high vs. low levels of Trend.
    (I would like to see the effect of value of Experience in high vs. low trend levels)

    First, I ran the regression of value on Trend, Experience, Interaction, and my controls,

    Second, I used the following code:
    margins, at(Trend=(2.09 4.53) Experience =(0 .75 1.5 2.25))
    In the Parentheses, I added for Trend the average +/- standard-deviation; and for Experience few observations to generate scenarios for the graph.

    To obtain the Graph, I then added the following code:
    marginsplot, xdimension(Experience) recastci(rarea)

    This resulted in two lines that are perfectly parallel with their areas that are perfectly similar. I have repeated this exercise using Excel and the results are not the same. Specifically, the slope of the two lines (at 2.09 and 4.53) are not the same.

    Can anyone advise what could be the problem in the code? Thanks.

  • #2
    Michael Mitchell has a nice book on "Interpreting and Visualizing Regression Models Using Stata". Chapter 5 discuss continuous by continuous interactions, and gives a first example:


    Code:
    net from http://www.stata-press.com/data/ivrm/
    net install ivrm
    use gss_ivrm
    keep if (age>22 & age<55) & (educ>=12)
    regress realrinc c.educ##c.age i.female, vce(robust)
    margins, at(age=(22 55) educ=(12(2)20))
    marginsplot, noci legend(rows(2) title(Education))

    Comment


    • #3
      Whenever you ask questions on a technical forum like this you need to tell exactly what you typed. The devil with this type of problems is in the details. You did not tell us what you typed to estimate your model, and now we need to guess.

      My guess is that you did not included the interaction using the factor variable notation. This is necessary as margins needs to know that your interaction term is an interaction term.
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Thanks,
        I typed the following
        reg value Trend Experience Interaction and controls...
        margins, at(Trend=(2.09 4.53) Experience =(0 .75 1.5 2.25))
        marginsplot, xdimension(Experience) recastci(rarea)

        As I read you, I may need to add something about interaction in "margins"?

        Comment


        • #5
          apparently you formed the interaction variable yourself; as Maarten wrote above (#3), this will not give you what you want; you need to use factor variable notation; see
          Code:
          help fvvarlist
          using such notation, your model, assuming that both Trend and Experience are continuous, would start like:
          Code:
          regress value c.Trend##c.Experience ...
          now you can use margins and marginsplot or even -marginscontplot-; for more on this, type
          Code:
          help marginscontplot
          and follow the instructions to install this user-written program

          Comment


          • #6
            I confirm. I have done the interaction myself.
            I have done so, because my interaction term uses mean-centered variables. This allowed me to reduce potential multi-collinearities with the IVs.
            Is there a way to do it with the mean-centered interaction term?

            Comment


            • #7
              You can still used factor variable notation, for example, c.var1_centered#c.var2_centered.

              Note there is a nice SSC program called center you might use, e.g.,

              Code:
              center var1, generate(var1_centered)
              center var1, generate(var2_centered)
              regress Y c.var1_centered##c.var2_centered
              -Dave

              Comment


              • #8
                Thanks Dave. I have done that. However, the limitation is that the main IVs in the regression should not be centered.
                I mean: Value = Trend + Experience + Trend_centered x Experience_centered + Controls.
                When plotting interactions automatically with the suggested codes, I am not sure whether Stata takes into account "non-centered" main IV and "Centered" interaction.

                JC

                Comment


                • #9
                  Oh! I have not run regressions in this way and don't know the answer.

                  Comment


                  • #10
                    Why should the lower ordered terms not be centered? And why do you think that you have to center the variables before interacting them?

                    Note that, unless your data is extremely ill-conditioned, Stata should not have any difficulties, whatsoever, to fit the model without centering at all. You may, naturally, still use centered variables, but that will not affect the results you obtain. Likewise, the results, in terms of coefficients, will be exactly the same whether you use centered lower order terms or their uncentered form; the constant will be all that changes. However, if you want to use margins, you either need to include both the lower order terms and their interaction in centered or uncentered form.

                    Best
                    Daniel

                    Comment


                    • #11
                      I have followed Aiken and West 1991 to reduce potential multi-collinearities. I agree with your point. I have plotted the interactions with or without mean-centered interaction (as per the advice), and the graphs are similar (with a slight difference at the intercept level). Thanks.

                      Comment


                      • #12
                        Actually, the graphs should be exactly the same. Of course, you need to feed margins' at() option the corresponding values. The uncentered/original values cannot simply be plugged into the centered regression results but must be transformed accordingly. If done correctly, you should not observe any differences. Here is a toy example

                        Code:
                        // toy dataset
                        sysuse auto , clear
                        
                        // center (SSC) two predictors
                        center mpg turn
                        
                        // get the mean values
                        summarize mpg
                        local mean_mpg = r(mean)
                        
                        summarize turn
                        local mean_turn = r(mean)
                        
                        // original metric
                        regress price c.mpg##c.turn
                        margins , at(mpg  = (`= `mean_mpg'-1'  `mean_mpg'  `= `mean_mpg'+1')  ///
                                     turn = (`= `mean_turn'-1' `mean_turn' `= `mean_turn'+1'))
                        
                        // centered predictors
                        regress price c.c_mpg##c.c_turn
                        margins , at(c_mpg = (-1 0 1) c_turn = (-1 0 1))
                        Omitting most outpput, this yields

                        Code:
                        (output omitted)
                        ------------------------------------------------------------------------------
                                     |            Delta-method
                                     |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
                        -------------+----------------------------------------------------------------
                                 _at |
                                  1  |   6039.575    382.602    15.79   0.000     5289.688    6789.461
                                  2  |   5933.263   370.8573    16.00   0.000     5206.396     6660.13
                                  3  |   5826.951   386.7295    15.07   0.000     5068.975    6584.927
                                  4  |   5711.991   376.1846    15.18   0.000     4974.683      6449.3
                                  5  |   5572.874   389.4025    14.31   0.000     4809.659    6336.089
                                  6  |   5433.757   429.6832    12.65   0.000     4591.594    6275.921
                                  7  |   5384.408    386.528    13.93   0.000     4626.827    6141.989
                                  8  |   5212.486   424.8329    12.27   0.000     4379.829    6045.143
                                  9  |   5040.564   487.0429    10.35   0.000     4085.978    5995.151
                        ------------------------------------------------------------------------------
                        (output omitted)
                        ------------------------------------------------------------------------------
                                     |            Delta-method
                                     |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
                        -------------+----------------------------------------------------------------
                                 _at |
                                  1  |   6039.575    382.602    15.79   0.000     5289.688    6789.461
                                  2  |   5933.263   370.8573    16.00   0.000     5206.396     6660.13
                                  3  |   5826.951   386.7295    15.07   0.000     5068.975    6584.927
                                  4  |   5711.991   376.1846    15.18   0.000     4974.683      6449.3
                                  5  |   5572.874   389.4025    14.31   0.000     4809.659    6336.089
                                  6  |   5433.757   429.6832    12.65   0.000     4591.594    6275.921
                                  7  |   5384.408    386.528    13.93   0.000     4626.827    6141.989
                                  8  |   5212.486   424.8329    12.27   0.000     4379.829    6045.143
                                  9  |   5040.564   487.0429    10.35   0.000     4085.978    5995.151
                        ------------------------------------------------------------------------------
                        which marginsplot will use both times.

                        Best
                        Daniel

                        Comment


                        • #13
                          Many thanks. I have similar for both.

                          Comment


                          • #14
                            Originally posted by daniel klein View Post
                            Actually, the graphs should be exactly the same. Of course, you need to feed margins' at() option the corresponding values. The uncentered/original values cannot simply be plugged into the centered regression results but must be transformed accordingly. If done correctly, you should not observe any differences. Here is a toy example

                            Code:
                            // toy dataset
                            sysuse auto , clear
                            
                            // center (SSC) two predictors
                            center mpg turn
                            
                            // get the mean values
                            summarize mpg
                            local mean_mpg = r(mean)
                            
                            summarize turn
                            local mean_turn = r(mean)
                            
                            // original metric
                            regress price c.mpg##c.turn
                            margins , at(mpg = (`= `mean_mpg'-1' `mean_mpg' `= `mean_mpg'+1') ///
                            turn = (`= `mean_turn'-1' `mean_turn' `= `mean_turn'+1'))
                            
                            // centered predictors
                            regress price c.c_mpg##c.c_turn
                            margins , at(c_mpg = (-1 0 1) c_turn = (-1 0 1))
                            Omitting most outpput, this yields

                            Code:
                            (output omitted)
                            ------------------------------------------------------------------------------
                            | Delta-method
                            | Margin Std. Err. z P>|z| [95% Conf. Interval]
                            -------------+----------------------------------------------------------------
                            _at |
                            1 | 6039.575 382.602 15.79 0.000 5289.688 6789.461
                            2 | 5933.263 370.8573 16.00 0.000 5206.396 6660.13
                            3 | 5826.951 386.7295 15.07 0.000 5068.975 6584.927
                            4 | 5711.991 376.1846 15.18 0.000 4974.683 6449.3
                            5 | 5572.874 389.4025 14.31 0.000 4809.659 6336.089
                            6 | 5433.757 429.6832 12.65 0.000 4591.594 6275.921
                            7 | 5384.408 386.528 13.93 0.000 4626.827 6141.989
                            8 | 5212.486 424.8329 12.27 0.000 4379.829 6045.143
                            9 | 5040.564 487.0429 10.35 0.000 4085.978 5995.151
                            ------------------------------------------------------------------------------
                            (output omitted)
                            ------------------------------------------------------------------------------
                            | Delta-method
                            | Margin Std. Err. z P>|z| [95% Conf. Interval]
                            -------------+----------------------------------------------------------------
                            _at |
                            1 | 6039.575 382.602 15.79 0.000 5289.688 6789.461
                            2 | 5933.263 370.8573 16.00 0.000 5206.396 6660.13
                            3 | 5826.951 386.7295 15.07 0.000 5068.975 6584.927
                            4 | 5711.991 376.1846 15.18 0.000 4974.683 6449.3
                            5 | 5572.874 389.4025 14.31 0.000 4809.659 6336.089
                            6 | 5433.757 429.6832 12.65 0.000 4591.594 6275.921
                            7 | 5384.408 386.528 13.93 0.000 4626.827 6141.989
                            8 | 5212.486 424.8329 12.27 0.000 4379.829 6045.143
                            9 | 5040.564 487.0429 10.35 0.000 4085.978 5995.151
                            ------------------------------------------------------------------------------
                            which marginsplot will use both times.

                            Best
                            Daniel
                            Why the SD=-1/1 after centering the continuous variable?
                            Thank you!

                            Comment


                            • #15
                              Originally posted by smith Jason View Post
                              Why the SD=-1/1 after centering the continuous variable?
                              Thank you!
                              It's not. In my example, I was plotting the mean +/-1 unit for both the original metric and the centered variables.

                              Code:
                              ...
                              margins , at(mpg = (`= `mean_mpg'-1' `mean_mpg' `= `mean_mpg'+1') ...)
                              ...
                              margins , at(c_mpg = (-1 0 1) ...)
                              See how the first line reduces to the second if `mean_mpg' == 0?

                              Indeed #1 wants to plot +/-1 SD. If you want that

                              Code:
                              ...
                              // get the mean values and SD
                              summarize mpg
                              local mean_mpg = r(mean)
                              local sd_mpg = r(sd) // <- new
                              
                              summarize turn
                              local mean_turn = r(mean)
                              local sd_turn = r(sd) // <- new
                              
                              ...
                              margins , at(mpg = (`= `mean_mpg'-`sd_mpg'' `mean_mpg' `= `mean_mpg'+`sd_mpg'') ...)
                              ...
                              margins , at(c_mpg = (-`sd_mpg' 0 `sd_mpg') ...)

                              Comment

                              Working...
                              X