Announcement

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

  • graph with gap?

    Dear All, I draw the following graph,
    Code:
    clear
    
    set obs 100
    
    gen x = _n
    gen c = 50
    gen d = (x >= c)
    
    twoway (line d x if x < 49.9) (line d x if x >= 50), ///
    ylabel(#3) xline(50, lpattern(dash) noextend) xlabel(#10) legend(off)
    Click image for larger version

Name:	srd.png
Views:	1
Size:	25.3 KB
ID:	1427983

    The problem is that how can I fill the gap (as indicated by the red circle)? Thanks for your suggestions.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    Here's one approach.
    Code:
    clear
    
    set obs 101
    
    gen x = _n
    gen c = 50
    replace x = c-.00001 in 101
    sort x
    gen d = (x >= c)
    
    twoway (line d x if x < 50) (line d x if x >= 50), ///
    ylabel(#3) xline(50, lpattern(dash) noextend) xlabel(#10) legend(off)
    Click image for larger version

Name:	image_9818.png
Views:	1
Size:	50.9 KB
ID:	1427990

    Comment


    • #3
      Hi William, Great and thank you.
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment


      • #4
        I'd mention also the use of twoway function for plotting deterministic functions.

        Comment


        • #5
          Hi, Nick, Many thanks for your instruction. I have the following code for the same/similar graph.
          Code:
          twoway function d = 0, range(0 50) || function d = 1, range(50 100) ///
          ylabel(#3) xline(50, lpattern(dash) noextend) xlabel(#10) legend(off)
          Click image for larger version

Name:	srd1.png
Views:	1
Size:	43.5 KB
ID:	1428012

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

          Comment

          Working...
          X