Announcement

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

  • Margins - Marginsplot - Manipulation of color for each estimate


    Hello, I think I might be getting lost over a somewhat simple matter, and I apologize for the disturbance. After a regression and a margins operation, I want to create a graph, but I want to differentiate the color of the estimates. Below you'll find an example (short one) of the code.


    Code:
    reg test gender income geo
    margins gender, dydx(income)
    marginsplot, scheme(s1mono)
    Note gender (0) boys (1) girls
    Any suggestion?

  • #2
    You can use the options -plotdimension()- and -xdimension()- so that the plot is not rendered as one. If you need the connecting line, you can add it using -addplot()-.

    Code:
    webuse nhanes2, clear
    regress bpsystol i.sex##c.bmi
    margins sex, dydx(bmi)
    *NOTE SEX IS CODED 1=male 2=female (MARGINS HIGHLIGHTED)
    set scheme s1color
    marginsplot, xdim(sex) plotdim(sex) ///
    addplot(scatteri 1.446317 1 1.758291 2, lc(gray) lw(medium) recast(line) xlab("") xtitle("") leg(order(3 "Male" 4 "Female")))
    Res.:

    Code:
    . margins sex, dydx(bmi)
    
    Average marginal effects                                Number of obs = 10,351
    Model VCE: OLS
    
    Expression: Linear prediction, predict()
    dy/dx wrt:  bmi
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    bmi          |
             sex |
           Male  |   1.446317   .0771793    18.74   0.000     1.295031    1.597603
         Female  |   1.758291   .0527283    33.35   0.000     1.654933    1.861649
    ------------------------------------------------------------------------------
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	21.9 KB
ID:	1722594

    Last edited by Andrew Musau; 02 Aug 2023, 04:49.

    Comment

    Working...
    X