Announcement

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

  • join some specific points in a combined line graph

    Dear Stata users

    Here is the data example for my question.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(event_time LOM_l2h low_off_prev high_off_future LOM_h2l high_off_prev low_off_future)
    -14        .3  .3636364         1         .         .         .
    -13  .4445714 .45529565  .4636531  .5498161  .5538647  .4836202
    -12  .4327295  .4855207  .6099911  .5792925 .57581276 .43750185
    -11  .4895546  .5074797   .475239  .5086453 .55275226 .50982624
    -10  .5172898  .5198574  .5334975  .5421471 .54556763  .5689122
     -9  .4970294 .50766385  .5323885  .5474887  .5457824  .5366033
     -8 .50223225  .5201586  .5244355  .5632965 .56102276  .5553815
     -7  .4916985 .51048684  .4955479  .5635227  .5706884 .52678597
     -6  .4836836  .4992603 .54205084 .54794866  .5443441  .5232386
     -5  .4808232  .4977573  .5195156 .54516083  .5481579  .5091129
     -4  .4687037  .4838091  .5249665 .54742306  .5496201 .51288193
     -3  .4738744  .4872146 .52407557  .5367966  .5378292  .5230757
     -2 .47064805  .4770534  .5287989  .5337237   .533482  .5334283
     -1  .4790803  .4821606  .5397413 .54033774  .5428444   .511556
      0 .53636444  .4986189 .55069655  .4732322   .503444  .4835654
      1  .5214533  .4919491 .52321386  .4714149 .50900024  .4816726
      2 .51340526 .48649925 .50921935  .4735042  .5031114   .481038
      3 .50897354  .4964011  .5042692  .4747502 .51145256  .4794954
      4  .5134132   .479529  .5128443  .4728722  .5028022  .4713624
      5  .4920339  .4910946  .4983232  .4836215 .50921834  .4826125
      6  .5086147  .4876752  .5031357  .4796166 .51263535 .48909625
      7 .51001245  .4494952  .5009839  .4843147  .4785838  .4848895
      8 .51033795  .4306166 .51097775  .4886848 .49674925  .4898983
      9  .4946199  .4971439  .4936177  .4623711  .4739278  .4633144
     10 .53731185   .458662  .5320845 .45194265  .4503594   .451997
     11  .4990519  .5097955  .4915094  .4126871  .3646617   .413646
     12  .5065789  .4100477  .4955752         .         .         .
     13  .4983607   .413646  .5168539         .         .         .
    end
    And the code for combined line graph is below:

    Code:
    keep if inrange(event_time,-4,4)        
    line     LOM_l2h         event_time if event_time<0, lp(solid) lc(blue) || ///
    line     LOM_l2h         event_time if event_time>=0, lp(solid) lc(blue) || ///
    line     LOM_l2h         event_time if inrange(event_time,-1,0), lp(dash) lc(blue) || ///
    line     low_off_future     event_time if inrange(event_time,0,4), lp(dash)  lc(green)  || ///
    line     high_off_prev     event_time if inrange(event_time,-4,-1), lp(dash) lc(red) xline(-1)
    which produced the following graph
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	36.5 KB
ID:	1770758



    However, I want to extend the upper red dashed line from event_time==-1 to the solid blue line (upper) at event_time==0. Similarly, lower green dashed line from event_time==0 to the solid blue line (lower) at event_time==-1. How can I do that?

    Thanks in advance.

    Zariab Hossain
    Uppsala University
    Last edited by Zariab Hossain; 14 Jan 2025, 08:17.

  • #2
    Underlining in passing that red and green should not be combined -- see e.g. https://www.tableau.com/en-gb/blog/e...green-together -- the easiest way to do this may be to fire up
    scatteri to add in extra line segments.

    Comment


    • #3
      Hi Nick,

      I solved that with scatteri. Thanks a lot for your quick suggestion,

      Regards,
      Zariab

      Comment

      Working...
      X