Announcement

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

  • Help in two way charts

    Hi,

    I am using Stata version 16 and need to do a unique two way chart. Below is a subset of my data:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str10 observation_date int unemploy long payems float unrate byte(peaks troughs plucking_rec) float(date datem)
    "01/01/1948" 2034 44679 3.4 1 0 0 -4383 -144
    "01/02/1948" 2328 44533 3.8 0 0 1 -4352 -143
    "01/03/1948" 2399 44683   4 0 0 1 -4323 -142
    "01/04/1948" 2386 44379 3.9 0 0 1 -4292 -141
    "01/05/1948" 2118 44796 3.5 0 0 1 -4262 -140
    "01/06/1948" 2214 45034 3.6 0 0 1 -4231 -139
    "01/07/1948" 2213 45160 3.6 0 0 1 -4201 -138
    "01/08/1948" 2350 45178 3.9 0 0 1 -4170 -137
    "01/09/1948" 2302 45294 3.8 0 0 1 -4139 -136
    "01/10/1948" 2259 45245 3.7 0 0 1 -4109 -135
    "01/11/1948" 2285 45192 3.8 0 0 1 -4078 -134
    "01/12/1948" 2429 45032   4 0 0 1 -4048 -133
    "01/01/1949" 2596 44668 4.3 0 0 1 -4017 -132
    "01/02/1949" 2849 44497 4.7 0 0 1 -3986 -131
    "01/03/1949" 3030 44240   5 0 0 1 -3958 -130
    "01/04/1949" 3260 44236 5.3 0 0 1 -3927 -129
    "01/05/1949" 3707 43984 6.1 0 0 1 -3897 -128
    "01/06/1949" 3776 43739 6.2 0 0 1 -3866 -127
    "01/07/1949" 4111 43531 6.7 0 0 1 -3836 -126
    "01/08/1949" 4193 43624 6.8 0 0 1 -3805 -125
    "01/09/1949" 4049 43780 6.6 0 0 1 -3774 -124
    "01/10/1949" 4916 42942 7.9 0 1 1 -3744 -123
    "01/11/1949" 3996 43242 6.4 0 0 0 -3713 -122
    "01/12/1949" 4063 43522 6.6 0 0 0 -3683 -121
    "01/01/1950" 4026 43526 6.5 0 0 0 -3652 -120
    "01/02/1950" 3936 43297 6.4 0 0 0 -3621 -119
    "01/03/1950" 3876 43954 6.3 0 0 0 -3593 -118
    "01/04/1950" 3575 44382 5.8 0 0 0 -3562 -117
    "01/05/1950" 3434 44718 5.5 0 0 0 -3532 -116
    "01/06/1950" 3367 45083 5.4 0 0 0 -3501 -115
    "01/07/1950" 3120 45454   5 0 0 0 -3471 -114
    "01/08/1950" 2799 46192 4.5 0 0 0 -3440 -113
    "01/09/1950" 2774 46438 4.4 0 0 0 -3409 -112
    "01/10/1950" 2625 46706 4.2 0 0 0 -3379 -111
    "01/11/1950" 2589 46776 4.2 0 0 0 -3348 -110
    "01/12/1950" 2639 46861 4.3 0 0 0 -3318 -109
    "01/01/1951" 2305 47288 3.7 0 0 0 -3287 -108
    "01/02/1951" 2117 47577 3.4 0 0 0 -3256 -107
    "01/03/1951" 2125 47873 3.4 0 0 0 -3228 -106
    "01/04/1951" 1919 47861 3.1 0 0 0 -3197 -105
    "01/05/1951" 1856 47952   3 0 0 0 -3167 -104
    "01/06/1951" 1995 48064 3.2 0 0 0 -3136 -103
    "01/07/1951" 1950 48061 3.1 0 0 0 -3106 -102
    "01/08/1951" 1933 48012 3.1 0 0 0 -3075 -101
    "01/09/1951" 2067 47954 3.3 0 0 0 -3044 -100
    "01/10/1951" 2194 48006 3.5 0 0 0 -3014  -99
    "01/11/1951" 2178 48147 3.5 0 0 0 -2983  -98
    "01/12/1951" 1960 48314 3.1 0 0 0 -2953  -97
    "01/01/1952" 1972 48296 3.2 0 0 0 -2922  -96
    "01/02/1952" 1957 48522 3.1 0 0 0 -2891  -95
    "01/03/1952" 1813 48504 2.9 0 0 0 -2862  -94
    "01/04/1952" 1811 48620 2.9 0 0 0 -2831  -93
    "01/05/1952" 1863 48642   3 0 0 0 -2801  -92
    "01/06/1952" 1884 48282   3 0 0 0 -2770  -91
    "01/07/1952" 1991 48143 3.2 0 0 0 -2740  -90
    "01/08/1952" 2087 48924 3.4 0 0 0 -2709  -89
    "01/09/1952" 1936 49320 3.1 0 0 0 -2678  -88
    "01/10/1952" 1839 49597   3 0 0 0 -2648  -87
    "01/11/1952" 1743 49816 2.8 0 0 0 -2617  -86
    "01/12/1952" 1667 50166 2.7 0 0 0 -2587  -85
    "01/01/1953" 1839 50144 2.9 0 0 0 -2556  -84
    "01/02/1953" 1636 50339 2.6 0 0 0 -2525  -83
    "01/03/1953" 1647 50473 2.6 0 0 0 -2497  -82
    "01/04/1953" 1723 50435 2.7 0 0 0 -2466  -81
    "01/05/1953" 1596 50490 2.5 1 0 0 -2436  -80
    "01/06/1953" 1607 50519 2.5 0 0 1 -2405  -79
    "01/07/1953" 1660 50536 2.6 0 0 1 -2375  -78
    "01/08/1953" 1665 50489 2.7 0 0 1 -2344  -77
    "01/09/1953" 1821 50368 2.9 0 0 1 -2313  -76
    "01/10/1953" 1974 50240 3.1 0 0 1 -2283  -75
    "01/11/1953" 2211 49908 3.5 0 0 1 -2252  -74
    "01/12/1953" 2818 49703 4.5 0 0 1 -2222  -73
    "01/01/1954" 3077 49469 4.9 0 0 1 -2191  -72
    "01/02/1954" 3331 49382 5.2 0 0 1 -2160  -71
    "01/03/1954" 3607 49157 5.7 0 0 1 -2132  -70
    "01/04/1954" 3749 49179 5.9 0 0 1 -2101  -69
    "01/05/1954" 3767 48965 5.9 0 0 1 -2071  -68
    "01/06/1954" 3551 48895 5.6 0 0 1 -2040  -67
    "01/07/1954" 3659 48835 5.8 0 0 1 -2010  -66
    "01/08/1954" 3854 48826   6 0 0 1 -1979  -65
    "01/09/1954" 3927 48886 6.1 0 1 1 -1948  -64
    "01/10/1954" 3666 48942 5.7 0 0 0 -1918  -63
    "01/11/1954" 3402 49180 5.3 0 0 0 -1887  -62
    "01/12/1954" 3196 49331   5 0 0 0 -1857  -61
    "01/01/1955" 3157 49496 4.9 0 0 0 -1826  -60
    "01/02/1955" 2969 49644 4.7 0 0 0 -1795  -59
    "01/03/1955" 2918 49962 4.6 0 0 0 -1767  -58
    "01/04/1955" 3049 50248 4.7 0 0 0 -1736  -57
    "01/05/1955" 2747 50512 4.3 0 0 0 -1706  -56
    "01/06/1955" 2701 50790 4.2 0 0 0 -1675  -55
    "01/07/1955" 2632 50987   4 0 0 0 -1645  -54
    "01/08/1955" 2784 51111 4.2 0 0 0 -1614  -53
    "01/09/1955" 2678 51266 4.1 0 0 0 -1583  -52
    "01/10/1955" 2830 51429 4.3 0 0 0 -1553  -51
    "01/11/1955" 2780 51592 4.2 0 0 0 -1522  -50
    "01/12/1955" 2761 51805 4.2 0 0 0 -1492  -49
    "01/01/1956" 2666 51975   4 0 0 0 -1461  -48
    "01/02/1956" 2606 52167 3.9 0 0 0 -1430  -47
    "01/03/1956" 2764 52294 4.2 0 0 0 -1401  -46
    "01/04/1956" 2650 52375   4 0 0 0 -1370  -45
    end
    format %td date
    format %tm datem
    I want a few things in my charts:

    1) How can I tell Stata that the position of the line corresponds to a specific date? I need a line for peak and a line for trough in the chart. As long as date has peak or trough =1, a line would be created in the chart. So for example if may 1953 has peak =1, I would like that indicated in the chart by creating a vertical line in the chart and the date indicated in the chart and if sept 1954 has trough = 1, a line and the date indicated in the chart too.

    2) Are there ways to shade the area between the lines? So I would like to see the area between a peak and a trough shaded grey: between the lines the area is shaded grey.



    Any help in this area would be appreciated. Thanks!

  • #2
    Btw, I am plotting unemployment(unrate) using tsline

    Comment


    • #3
      Click image for larger version

Name:	Example_chart.PNG
Views:	1
Size:	314.5 KB
ID:	1596347


      Ideally, I would like the time series plot to similar to this example with the dates displayed too. Main issue I had is that I don't know the codes to create such plots and have to reply on the graph editor to add in the vertical lines. Any help in the cods would be appreciated. Thanks!

      Comment


      • #4
        This is a common problem. See https://blog.stata.com/2020/02/13/ad...series-graphs/ and its references for many detailed suggestions.

        Comment

        Working...
        X