Announcement

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

  • Interaction plots of continuous variables

    Hello everyone!

    I am having issues with constructing an interaction plot. I have been reading some advice on earlier problems on this forum but have not found what I needed yet. But let me first give you how my regression looks like (I am working with panel data):

    xtset country year, yearly

    xtreg percentOE QT QL EPL QTEPL QLEPL CV1 CV2 CV3, fe vce (robust)
    • percentOE is the dependent variable
    • QT, QL and EPL are the independent variables
    • QTEPL and QLEPL are the interaction effects
    • CV1, CV2 and CV3 are the control variables
    All the variables are continuous variables, what makes plotting the interaction effect more difficult for me. I would like to plot QTEPL and QLEPL each on an interaction plot. My best success so far was using the contour command. Yet, this was not that clear to interpret. Moreover, I am questioning what to put on the axis to provide the best view on the interaction effects.

    If anyone would have seen this issue before and see a (perhaps easy) solution, I'd be very grateful!

    Best,

    Stijn


  • #2
    Hey Stijn,

    I`d try the predict command to get the predictions and then plot them, yet that depends on your research question. What exactly do you want to show by plotting the interaction variables? Why do you want to plot them
    (see: https://www.stata.com/manuals13/xtxt...estimation.pdf)

    Code:
    //Store predictions for your fixed effects modell in variable predfix
    predict predfix
    //Plot two graphs with predictions for your two interaction variables 
    sort country year
    twoway (line predfix QTEPL, connect(ascending))
    twoway (line predfix QLEPL, connect(ascending))
    It would be a bit easier if you'd post the Stata output and/or your data to the group, so people can work with it and try the commands they want to provide for you.

    Regards,

    Benedikt

    Comment


    • #3
      Already thank you Benedikt for your comments

      I want to determine the impact of investments (measured by the variables QL and QT) on the incidence of overeducation (measured by percentOE). I have found a significant effect for these investments but it is mitigated by the degree of labour market flexibility (measured by EPL). What I want to show is how this interaction effect influences the impact investments have on the incidence of overeducation. I have posted the outcome of the xtreg underneath and I will post my data as well after I have figured out how to do so and not get an error message. I hope this can offer a bit more clarity.


      Click image for larger version

Name:	Outcome.PNG
Views:	1
Size:	29.7 KB
ID:	1442807

      Comment


      • #4
        Hi, Stijn, You might find the following website helpful (http://yiqingxu.org/software.html).
        Ho-Chuan (River) Huang
        Stata 19.0, MP(4)

        Comment


        • #5
          The easy way to do this is to re-run your regression using factor variable notation and then use -margins- and -marginsplot-. So first you have to get rid of your hand-calculated interaction terms:

          Code:
          xtreg percentOE (c.QT c.QL)##c.EPL  CV1 CV2 CV3, fe vce (robust)
          Next pick ranges of interesting values of QT, QL, and EPL; typically one choses several values that span the range of values observed in the data, at least approximately, perhaps avoiding the extremes, and sometimes with a greater concentration in areas that are of particular practical importance. Then you do

          Code:
          margins, dydx(QT QL) at(QT = (interesting_values_of_QT) QL = (interesting_values_of_QL) ///
              EPL = (interesting_values_of_EPL))
          marginsplot, xdimension(EPL)
          This will give you graphs of the marginal effects of QT and QL on percentOE as functions of EPL. You might also be interested in showing the expected values of percentOE at these same combinations. That would be:
          Code:
          margins, at(QT = (interesting_values_of_QT) QL = (interesting_values_of_QL) ///
              EPL = (interesting_values_of_EPL))
          marginsplot, xdimension(EPL)
          -marginsplot- accepts almost all options available for -graph twoway- so you can customize the appearance of the graph to your taste.

          Comment


          • #6
            Thank you Clyde, it shows perfectly what I want! I appreciate it!

            Comment

            Working...
            X