Announcement

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

  • Issue with line chart options

    Hello and thanks for the help.
    I am using this code to generate the 5 attached charts:

    * Set some global options for graphs (recessions, country names...)
    global countries_europe_EA `" "DE" "ES" "FR" "IT" "EA" "'
    global name_DE "Germany"
    global name_ES "Spain"
    global name_FR "France"
    global name_IT "Italy"
    global name_EA "Euro Area"
    * Label horizontal axis
    global xlabel_DE xlabel(`=tq(1995q1)' (12) `=tq(2020q4)', format(%tqCY) nogrid)
    global xlabel_ES xlabel(`=tq(1995q1)' (12) `=tq(2020q4)', format(%tqCY) nogrid)
    global xlabel_FR xlabel(`=tq(1995q1)' (12) `=tq(2020q4)', format(%tqCY) nogrid)
    global xlabel_IT xlabel(`=tq(1995q1)' (12) `=tq(2019q4)', format(%tqCY) nogrid)
    global xlabel_EA xlabel(`=tq(1995q1)' (12) `=tq(2019q4)', format(%tqCY) nogrid)

    * Legend
    global legend_DE legend(bplacement(nw))
    global legend_ES legend(bplacement(sw))
    global legend_FR legend(bplacement(nw))
    global legend_IT legend(bplacement(sw))
    global legend_EA legend(bplacement(nw))


    foreach c of global countries_europe_EA {
    gen recession_`c' = recessions if country == "`c'"
    bgshade date, shaders(recession_`c') sstyle(lc(gs14) lpattern(solid)) ///
    twoway ((line Z_Solow date, lcolor(black) lpattern(shortdash) lwidth(thick)) ///
    (line Z_tv date, lcolor(lime%100*0.8) lpattern(solid) lwidth(thick)) if country == "`c'", ///
    graphregion(color(white)) bgcolor(white) xtitle(Year) ytitle("Cumulated Growth (log changes)") ///
    xscale(titlegap(0) outergap(0) lwidth(medthin) lcolor(black)) yscale(titlegap(1) outergap(0) lwidth(medthin) lcolor(black)) ylabel(,nogrid) ///
    xtick(,tlcolor(black) tlwidth(medthin)) ytick(,tlcolor(black) tlwidth(medthin)) ${legend_`c'} title("{bf:${name_`c'}}") ${xlabel_`c'} ///
    legend(label(2 "Our series") label(1 "Solow") cols(1) ring(0) region(margin(zero) color(none))))
    graph export "$export_directory/tfplevels_`c'.eps", replace
    drop recession_`c'
    }

    After running this code, I am able to generate the graphs (you can see them from the screenshot). However, there are some options that seem not working properly.
    The location of the legend does not work, since the legend is always shown on the righten part of the graph, not sw or nw
    The charts for Germany, Spain and France show a 2 at the end of the x-axis. However, there should not be any number, since the graph should stop at 2020q4.
    Lastly, the content of the legend is not correct, since it shows BFK instead of Our series.
    Attached Files

  • #2
    Hi, Riccardo Meli, I enjoy your detailed and elegant codes. And I use an artificial data introduced in -bgshade- helpfile to test your codes, and they runs sucecessfully. All globals, legends, parenthesis are works well.
    Code:
    . which bgshade
    c:\ado\plus\b\bgshade.ado
    *! version 1.0 Eric Haavind-Berman 12July2017
    
    drop _all
    set obs 2000
    gen date = _n-1280
    format date %tm
    gen series = sqrt(_n)+runiform()
    gen series2 = series*runiform()/2
    
    global name_DE "Germany"
    global legend_DE legend(bplacement(nw))
    global xlabel_DE xlabel(`=tq(1995q1)' (12) `=tq(2020q4)', format(%tqCY) nogrid)
    
    set scheme s2color
    
    bgshade date, shaders(month) sstyle(lc(gs14) lpattern(solid)) ///
        twoway ((line series date, lcolor(black) lpattern(shortdash) lwidth(thick)) ///
        (line series2 date, lcolor(lime%100*0.8) lpattern(solid) lwidth(thick)), ///
        graphregion(color(white)) bgcolor(white) xtitle(Year) ytitle("Cumulated Growth (log changes)") ///
        xscale(titlegap(0) outergap(0) lwidth(medthin) lcolor(black)) yscale(titlegap(1) outergap(0) lwidth(medthin) lcolor(black)) ylabel(,nogrid) ///
        xtick(,tlcolor(black) tlwidth(medthin)) ytick(,tlcolor(black) tlwidth(medthin)) ${legend_DE} title("{bf:${name_DE}}") ${xlabel_ED} ///
        legend(label(2 "Our series") label(1 "Solow") cols(1) ring(0) region(margin(zero) color(none))))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	385.7 KB
ID:	1775932

    Comment

    Working...
    X