Announcement

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

  • How to visualize the marginal effect of interaction term?

    Dear all, I would like to ask you how can you visualize "the marginal effect" of two variables which were in interaction. I am using screen shot from article of Brambor2005:

    Click image for larger version

Name:	ss1.png
Views:	1
Size:	18.9 KB
ID:	1453608


    Which is based on this reg. model:

    Click image for larger version

Name:	ss2.png
Views:	1
Size:	36.5 KB
ID:	1453609


    I am hundred percent positive It can be done in Stata, but I was not able to find and recommendation or guide how to do so. I am glad for any help.

  • #2
    Code:
    sysuse nlsw88, clear
    gen byte black = race == 2 if race <=2
    label define black 0 "white" 1 "black"
    label value black black
    reg wage i.black##c.grade ttl_exp i.south i.union
    margins, dydx(black) at(south=0 union=0 ttl_exp=10) over(grade)
    marginsplot, yline(0)
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you for your answer, but to be honest, I am unable to read the code properly. Can you elaborate a bit on which of those words can, or better, should be rewritten, so I can adapt it to my dataset? Thanks.

      Comment


      • #4
        The first line opens an example dataset that comes with Stata

        line 2-4 create a new variable for race distinguishing only between blacks and whites

        line 5 estimates the regression with interaction effect between black and grade

        line 6 computes the effect of black for different values of grade

        line 7 plots this in a graph

        You may want to look at help fvvarlist , help margins , and help marginsplot
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Thanks a lot, I will surely look at the urls (edit: help commands), but just to be sure, one quick question. I have only scale variables, is the code same for this situation?
          Last edited by Karel Novak; 16 Jul 2018, 10:58.

          Comment


          • #6
            For continuous variables you use the c. prefix (like c.grade) and for categorical variables you use the i. prefix (like i.black). See help fvvarlist.
            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment


            • #7
              In general, if you want us to provide code that fits your problem, you need to provide us with example data that fits your problem. Otherwise, we are forced to use generic example data. See the FAQ on how to provide such example data.
              ---------------------------------
              Maarten L. Buis
              University of Konstanz
              Department of history and sociology
              box 40
              78457 Konstanz
              Germany
              http://www.maartenbuis.nl
              ---------------------------------

              Comment

              Working...
              X