Announcement

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

  • second y-axis with xtline

    Hi everybody,
    I have a panel data with four countries and I want to use the xtline graph with the overlay option.
    I would like to use the left axis for three countries of my panel and the right axis for the fourth.
    Can somebody tell me how to include a second y-axis on the xtline graph, with values corresponding to the fourth country data?
    Thank you very much.
    Gilles

  • #2
    Here's an example using the system data census.dta (note the use of axis(2) below) :


    Code:
    sysuse census, clear
    set scheme s1mono
    
    *panel here is region, not country
    bys region : g time = _n
        *assuming you want a different axis b/c of scaling diff
        replace pop = pop*(runiform()*7) if region ==4
        tabstat pop, by(region) s(min max mean sd)
    xtset region time
    
    **
    twoway ///
     (connected pop time if region ==1, sort) ///
     (connected pop time if region ==2, sort) ///
     (connected region time if region==3, sort) ///
     (connected pop time if region==4, sort yaxis(2)) , ///
        ytitle(Region 1/3 Pop) ytitle(Region 4 Pop, axis(2)) ///
        ylabel(#4, labsize(vsmall) alternate) ///
        ylabel(#4, labsize(vsmall) alternate axis(2)) ///
        legend(on order(1 "Reg1" 2 "Reg2" 3 "Reg3" 4 "REG4")  r(1))
    Produces the attached graph.
    Attached Files
    Last edited by eric_a_booth; 28 Mar 2016, 12:00.
    Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

    Comment


    • #3
      Thank you Eric

      Comment

      Working...
      X