Announcement

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

  • Summarizing margins plots

    Hello

    Is there a way of using margins or some other command to represent in summary (e.g. in one bar with SEs) how marginal effects of one variable change as the values of another variable do?

    For background, I have been showing the following ME of var1 for different values of var2


    Code:
    reg var0 c.var1##c.var2
    
    margins , dydx(var1) at(var2=(0(1)10))
    
    marginsplot

    Instead of showing the x-axis varying from 0-10, I would like to capture in a bar chart (with one bar and SEs) the difference in the ME of var1 when var2 goes from 0 to 10, i.e. ME(var1(var2=10)-ME(var1(var2=0)



    Thanks so much in advance!

  • #2
    Does this get you at least part way there?

    Code:
    clear
    webuse auto
    reg mpg c.weight##c.length
    margins, dydx(weight) at (length=(60(10)80))  coeflegend post
    lincom  _b[weight:1bn._at] -  _b[weight:3._at]
    Devra Golbe
    Professor Emerita, Dept. of Economics
    Hunter College, CUNY

    Comment


    • #3
      Thanks Devra, this was exactly what I needed! --I was not familiar with the lincom command that is very helpful in this case.

      For others' reference, you can obtain the estimate in the way Devra suggested and then plot it with CI through twoway bar and rcap, as follows:

      Code:
       frame create ors4 xvalue yvalue lb ub  
      
      //(Devra's reg, margins and lincom command here)
      
      frame post ors (1) (r(estimate)) (r(lb)) (r(ub))  
      
      frame change ors4 graph
      
      twoway (bar  yvalue xvalue) (rcap orlb orub xvalue)
      (For more detail see post in this forum here)
      Last edited by Carlos Anadon; 29 Aug 2022, 04:23.

      Comment


      • #4
        You're welcome! I tried running your code, and I believe it has a couple of typos:
        Code:
         
         frame change ors4 graph
        produces the error: 'graph' found where nothing expected."

        I assume the "graph" goes with the next statement:

        Code:
        graph twoway (bar  yvalue xvalue) (rcap lb ub xvalue)

        where I have also replaced orlb and orub with lb and ub respectively.

        For completeness:

        Code:
        clear all
        webuse auto
        frame create ors4 xvalue yvalue lb ub  
        reg mpg c.weight##c.length
        margins, dydx(weight) at (length=(60(10)80))  coeflegend post
        lincom  _b[weight:1bn._at] -  _b[weight:3._at]
        frame post ors4 (1) (r(estimate)) (r(lb)) (r(ub))  
        frame change ors4
        graph twoway (bar  yvalue xvalue) (rcap lb ub xvalue)
        Is that what you meant?
        Devra Golbe
        Professor Emerita, Dept. of Economics
        Hunter College, CUNY

        Comment

        Working...
        X