Announcement

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

  • time series plots

    Dear All, I have this data set:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(year etime) double henry
    2020 -15 1.83
    2020 -14 1.84
    2020 -13 1.82
    2020 -12 1.87
    2020 -11 1.86
    2020 -10 1.86
    2020  -9 1.86
    2020  -8 1.77
    2020  -7 1.84
    2020  -6 1.83
    2020  -5 1.84
    2020  -4 1.98
    2020  -3 1.96
    2020  -2 1.92
    2020  -1 1.91
    2020   0 1.83
    2020   1 1.85
    2020   2 1.82
    2020   3 1.75
    2020   4 1.68
    2020   5 1.76
    2020   6  1.8
    2020   7 1.83
    2020   8 1.77
    2020   9 1.71
    2020  10 1.78
    2020  11 1.94
    2020  12 1.88
    2020  13 1.84
    2020  14 1.87
    2020  15 1.82
    2021 -15 2.85
    2021 -14 2.79
    2021 -13 2.94
    2021 -12 2.86
    2021 -11 2.88
    2021 -10 2.84
    2021  -9 2.91
    2021  -8 2.87
    2021  -7 2.91
    2021  -6 3.13
    2021  -5 3.22
    2021  -4 3.08
    2021  -3 3.07
    2021  -2 2.95
    2021  -1 2.88
    2021   0 2.85
    2021   1 2.78
    2021   2 2.77
    2021   3 2.78
    2021   4 2.84
    2021   5 2.82
    2021   6 2.75
    2021   7  2.7
    2021   8 2.66
    2021   9 2.66
    2021  10 2.69
    2021  11 2.67
    2021  12  2.6
    2021  13 2.48
    2021  14 2.56
    2021  15 2.53
    2022 -15  5.5
    2022 -14 4.89
    2022 -13 4.57
    2022 -12 4.23
    2022 -11 4.25
    2022 -10 4.01
    2022  -9 3.96
    2022  -8 3.94
    2022  -7  4.2
    2022  -6 4.31
    2022  -5 4.72
    2022  -4 4.49
    2022  -3 4.43
    2022  -2  4.5
    2022  -1 4.62
    2022   0 4.57
    2022   1 4.47
    2022   2  4.4
    2022   3 4.57
    2022   4 4.76
    2022   5 4.72
    2022   6 5.02
    2022   7 4.83
    2022   8 4.53
    2022   9 4.53
    2022  10 4.63
    2022  11 4.73
    2022  12 4.66
    2022  13 4.57
    2022  14 4.75
    2022  15 4.99
    end
    The dependent variable (y) is `henry', and the indepdnent variable is `etime'. For each year (2020, 2021, and 2022), there is a plot (with year explicitly appears on the right-hand side). Moreover, a vertical line when etime=0 should be drawn. Finally, in the 2022 and etime >= 0, the line is with different colors/styles, compared with the other parts (say, 2022 & etime < 0, and year 2021, 2020). Any suggestions are appreciated.

    Note, a similar (not so complete) plot is here: . .
    Click image for larger version

Name:	henry.png
Views:	1
Size:	52.8 KB
ID:	1695574
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(year etime) double henry
    2022   0 4.57
    2022   1 4.47
    2022   2  4.4
    2022   3 4.57
    2022   4 4.76
    2022   5 4.72
    2022   6 5.02
    2022   7 4.83
    2022   8 4.53
    2022   9 4.53
    2022  10 4.63
    2022  11 4.73
    2022  12 4.66
    2022  13 4.57
    2022  14 4.75
    2022  15 4.99
    2022 -15  5.5
    2022 -14 4.89
    2022 -13 4.57
    2022 -12 4.23
    2022 -11 4.25
    2022 -10 4.01
    2022  -9 3.96
    2022  -8 3.94
    2022  -7  4.2
    2022  -6 4.31
    2022  -5 4.72
    2022  -4 4.49
    2022  -3 4.43
    2022  -2  4.5
    2022  -1 4.62
    2021 -15 2.85
    2021 -14 2.79
    2021 -13 2.94
    2021 -12 2.86
    2021 -11 2.88
    2021 -10 2.84
    2021  -9 2.91
    2021  -8 2.87
    2021  -7 2.91
    2021  -6 3.13
    2021  -5 3.22
    2021  -4 3.08
    2021  -3 3.07
    2021  -2 2.95
    2021  -1 2.88
    2021   0 2.85
    2021   1 2.78
    2021   2 2.77
    2021   3 2.78
    2021   4 2.84
    2021   5 2.82
    2021   6 2.75
    2021   7  2.7
    2021   8 2.66
    2021   9 2.66
    2021  10 2.69
    2021  11 2.67
    2021  12  2.6
    2021  13 2.48
    2021  14 2.56
    2021  15 2.53
    2020 -15 1.83
    2020 -14 1.84
    2020 -13 1.82
    2020 -12 1.87
    2020 -11 1.86
    2020 -10 1.86
    2020  -9 1.86
    2020  -8 1.77
    2020  -7 1.84
    2020  -6 1.83
    2020  -5 1.84
    2020  -4 1.98
    2020  -3 1.96
    2020  -2 1.92
    2020  -1 1.91
    2020   0 1.83
    2020   1 1.85
    2020   2 1.82
    2020   3 1.75
    2020   4 1.68
    2020   5 1.76
    2020   6  1.8
    2020   7 1.83
    2020   8 1.77
    2020   9 1.71
    2020  10 1.78
    2020  11 1.94
    2020  12 1.88
    2020  13 1.84
    2020  14 1.87
    2020  15 1.82
    end
    
    separate henry, by(year) veryshortlabel
    set scheme s1mono
    tw (line henry202? etime, sort) (line henry2022 etime if etime>=0, lc(green) sort) ///
    (scatter henry etime if etime==15, ms(none) mlab(year) leg(off) xline(0))
    Res.:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	26.9 KB
ID:	1695577

    Last edited by Andrew Musau; 02 Jan 2023, 01:05.

    Comment


    • #3
      Dear Andrew, Many thanks. BTW, how can I drop etime (legend)? And, how can I change the xlabel (say, from 15 to 15)/ylabel (say from 0 to 6)?
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment


      • #4
        Code:
        set scheme s1mono
        tw (line henry202? etime, sort) (line henry2022 etime if etime>=0, lc(green) sort) ///
        (scatter henry etime if etime==15, ms(none) mlab(year) leg(off) xline(0) xtitle("") ///
        xsc(r(-15 17)) xlab(-15(5) 15) ysc(r(0 6)) ylab(0/6))
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	27.1 KB
ID:	1695590

        Last edited by Andrew Musau; 02 Jan 2023, 02:45.

        Comment

        Working...
        X