Announcement

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

  • line graph at country and year level for several variables using levelsof

    Hello all,

    I have a panel long format dataset that can be found attached containing year and country and for each country I have a trade flow reported from different sources, 5 in total. So for each country I have 5 reported variables. I need to plot them all in one graph. So the graph must show each of the 5 variables for all the countries and for all the years. I already have the single graphs for each country showing all 5 variables. For that I used the following code:

    Code:
    use "$path\exports\_all2.dta", clear
    drop if 1850 > y
    drop if  y > 1955
    label variable expTRADHISTUSD "exports TRADHIST"
    label variable excow "exports COW"
    label variable expRICARDOUSD "exports Ricardo"
    label variable exptena "exports Tena"
    label variable exptena1913 "exports Tena 1913 borders"
    replace c = "Ivory Coast" if c == "Cote d'Ivoire"
    replace c = subinstr(c," ","",.)
    
    levelsof c, local(c1)
    foreach c of local c1 {
        twoway (line exptena y if c == "`c'") (line exptena1913 y if c == "`c'") (line expTRADHISTUSD y if c == "`c'") (line expRICARDOUSD y if c == "`c'") (line excow y if c == "`c'"), ytitle(, size(vsmall) orientation(rvertical)) ylabel(, labsize(small) angle(horizontal) tlength(zero)) ymtick(, nolabels) xtitle(year) xtitle(, size(small)) xscale(range(1850 1955)) xlabel(#25, labsize(vsmall)) title(`c' Exports (USD), size(small)) legend(size(vsmall)) name(`c')
    graph export "$path\exports/`c'.png", as(png) name("`c'") replace
        }
    but what I need is to have this all in one graph with the same y and x axes, i.e. all the line in one single cartesian board. So I don't want to combine them. Can anyone give me some ideas to proceed?

    Best,
    Shadi


    Attached Files

  • #2
    xtset the data and use xtline with the -overlay- option. See

    Code:
    help xtline

    Comment

    Working...
    X