Announcement

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

  • stepchart graph with time series values by year

    Hi stata users,
    I have some time series values and I want a graph with steps like that in the link:

    http://peltiertech.com/line-chart-without-risers/

    Do you know if there is a graph function?
    Regards

  • #2
    This can be done with the graph command (not a function). The data structure needed in Stata is similar to that in your source. Try

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str9 date float rate
    "14-Sep-75"  .1
    "31-Dec-75"  .1
    "31-Dec-75"   .
    "31-Dec-75" .13
    "29-May-78" .13
    "29-May-78"   .
    "29-May-78" .15
    "22-Mar-81" .15
    "22-Mar-81"   .
    "22-Mar-81" .18
    "1-Nov-81"  .18
    "1-Nov-81"    .
    "1-Nov-81"   .2
    "17-Feb-85"  .2
    "17-Feb-85"   .
    "17-Feb-85" .22
    "3-Apr-88"  .22
    "3-Apr-88"    .
    "3-Apr-88"  .25
    "3-Feb-91"  .25
    "3-Feb-91"    .
    "3-Feb-91"  .29
    "1-Jan-95"  .29
    "1-Jan-95"    .
    "1-Jan-95"  .32
    "10-Jan-99" .32
    "10-Jan-99"   .
    "10-Jan-99" .33
    "7-Jan-01"  .33
    "7-Jan-01"    .
    "7-Jan-01"  .34
    "30-Jun-02" .34
    "30-Jun-02"   .
    "30-Jun-02" .37
    "8-Jan-06"  .37
    "8-Jan-06"    .
    "8-Jan-06"  .39
    "14-May-07" .39
    "14-May-07"   .
    "14-May-07" .41
    "12-May-08" .41
    "12-May-08"   .
    "12-May-08" .42
    end
    gen ndate = daily(date, "DMY", 2050)
    format ndate %td
    twoway line rate ndate, cmissing(no) xla(, format(%tdCY)) xtitle("") yla(, ang(h))

    Comment


    • #3
      Thank you for your answer, Nick.
      there exist a way to: duplicate my yearly data; for every duplicated obs, gen a var with 1-jan-"year" and 31-dec-"year"; and finally, get a null obs between those pairs?
      If I get that I could use your code.
      Regards

      Comment


      • #4
        Code:
        help expand

        Comment


        • #5
          This is the code:

          Code:
          *ssc install expgen
          clear
          input str9 date float rate
          1960    
          1961    1.3
          1962    1.3
          1963    1.3
          1964    1.3
          1965    1.3
          1966    3.1
          1967    3.1
          1968    3.1
          1969    3.1
          1970    3.1
          1971    -3.2
          1972    -3.2
          1973    -3.2
          1974    -3.2
          1975    -3.2
          1976    5.1
          1977    5.1
          1978    5.1
          1979    5.1
          1980    5.1
          1981    -2.3
          1982    -2.3
          1983    -2.3
          1984    -2.3
          1985    -2.3
          1986    2.1
          1987    2.1
          1988    2.1
          1989    2.1
          1990    2.1
          1991    4.9
          1992    4.9
          1993    4.9
          1994    4.9
          1995    4.9
          1996    0.9
          1997    0.9
          1998    0.9
          1999    0.9
          2000    0.9
          2001    1
          2002    1
          2003    1
          2004    1
          2005    
          2006    
          2007    
          2008    
          2009    
          2010    
          2011    
          2012    
          2013    
          2014    
          2015    
          end
          
          
          expgen nreps=2
          gen ndate = daily(date, "Y", 2050)
          format ndate %td
          
          forvalues i = 2(2)88 {
              replace ndate = ndate[`i'+1] - 1 in `i'/`i'
              }
          
          twoway line rate ndate, cmissing(no) xla(, format(%tdCY)) xtitle("") yla(, ang(h))
          Last edited by Fernando Greve; 21 Mar 2016, 21:44.

          Comment


          • #6
            It was late my time zone when I posted, so I confined myself to a hint. For your data, this code suffices. I see no obvious point to importing a string year and converting it to a daily date.

            Code:
            clear
            input date rate
            1960    
            1961    1.3
            1962    1.3
            1963    1.3
            1964    1.3
            1965    1.3
            1966    3.1
            1967    3.1
            1968    3.1
            1969    3.1
            1970    3.1
            1971    -3.2
            1972    -3.2
            1973    -3.2
            1974    -3.2
            1975    -3.2
            1976    5.1
            1977    5.1
            1978    5.1
            1979    5.1
            1980    5.1
            1981    -2.3
            1982    -2.3
            1983    -2.3
            1984    -2.3
            1985    -2.3
            1986    2.1
            1987    2.1
            1988    2.1
            1989    2.1
            1990    2.1
            1991    4.9
            1992    4.9
            1993    4.9
            1994    4.9
            1995    4.9
            1996    0.9
            1997    0.9
            1998    0.9
            1999    0.9
            2000    0.9
            2001    1
            2002    1
            2003    1
            2004    1
            end 
            expand 2 if rate != rate[_n+1] 
            sort date 
            replace rate = . if date == date[_n-1] 
            line rate date, cmissing(no)

            Comment

            Working...
            X