Announcement

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

  • multiple lines in one graph with if conditions

    hi statalist,

    I have the following data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte period float(time var1)
    1 1 -.0004733252
    1 2  -.003605119
    1 3   -.02635961
    1 4   -.02870885
    1 5  -.029828776
    2 1 -.0006582998
    2 2 .00020854693
    2 3   -.02371385
    2 4   -.02286483
    2 5    -.0230184
    end
    label values time t
    label def t 1 "t-1", modify
    label def t 2 "t", modify
    label def t 3 "t+1", modify
    label def t 4 "t+2", modify
    label def t 5 "t+3", modify
    I want to make a graph with two lines.
    The first line should show var1 if period == 1 and the second line should show var1 if period == 2.
    The first line should be a solid line, the second a dashed line.
    x-axis should be time (t-1 to t+3), y-axis should be the values of var1.

    I tried with twoway but unfortunately didn't work.
    Any recommendation how to solve my problem?

  • #2
    Lukas, you may try this code.

    Code:
    twoway line var1 time if period == 1, lp(solid) || line var1 time if period == 2, lp(dash) xlabel(,val) legend(order(1 "period 1" 2 "period 2"))

    Comment

    Working...
    X