Announcement

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

  • Add a vertical line?

    Dear all, I generate a data set and estimate an interaction model as follows.
    Code:
    clear
    set seed 123
    set obs 1000
    gen x = runiform() 
    gen z = runiform() 
    gen xz = x*z
    
    // interaction model
    gen y1 = 1+3*x-2*z+1*xz+rnormal()
    reg y1 c.x##c.z, robust
    quietly margins, dydx(x) at(z=(0(0.1)1))
    quietly marginsplot, recast(line) recastci(rline) ciopts(lpattern(dash) lcolor(red)) yline(0)
    The graph is

    Click image for larger version

Name:	x-vertical.png
Views:	1
Size:	21.2 KB
ID:	1566062


    I wonder if we can add vertical lines, say at x=0 and x=0.5? Thanks.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    Yes, we can:
    Code:
    quietly marginsplot, recast(line) recastci(rline) ciopts(lpattern(dash) lcolor(red)) xline(0) xline(.5)

    Comment


    • #3
      Dear Joro, Thanks a lot. It helps.
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment


      • #4
        You are welcome. One more thing, both -xline- and -yline- can accept multiple space delimited arguments. Here we draw just two lines on the picture so it does not matter much, but if we are drawing many lines, multiple arguments re convenient. So the command below does the same as the command above:

        Code:
         quietly marginsplot, recast(line) recastci(rline) ciopts(lpattern(dash) lcolor(red)) xline(0 0.5)

        Comment


        • #5
          Dear Joro, Got it and thanks.

          Ho-Chuan (River) Huang
          Stata 19.0, MP(4)

          Comment

          Working...
          X