I want to draw a time series plot specifying reference lines for both X & Y axes. I could get the plot showing reference lines for the time (X) axis only (as shown in the following graph).
The command I used is twoway (tsline egg_prod), tline(2004 2007 2012)
Now I want to show the mean lines for each segment. i.e. the average egg production within 2004-2007 & 2008-2012.
I'm posting a minimal dataset for your reference. Following is the code I used with dataex.
clear
input int year long egg_production
2000 918000
2001 941000
2002 886000
2003 885012
2004 874596
2005 864552
2006 901176
2007 915600
2008 1.0e+06
2009 1.1e+06
2010 1.1e+06
2011 1.2e+06
2012 1.2e+06
2013 1.9e+06
end
Can someone suggest the way I should follow?
EDIT:
I now want to shade the area corresponding to each identified time period.
I tried the recast(area)
option but encountered some problems.
1) I want the shaded area to touch the top & bottom margins of the plot. I couldn’t find a way for that.
2) I don’t want to see a legend for shaded areas. So I used legend(off)
but that means that the legend related to the mean values is omitted too. Could you please suggest a way to figure out these issues?
graph twoway scatteri 2 2004 2 2007, recast(area) fcolor(gs14) lcolor(maroon) legend(off) ///
|| scatteri 2 2008 2 2012, recast(area) fcolor(gs14) lcolor(maroon) legend(off) ///
|| connected egg year, tline(2004 2007 2008 2012) ///
|| scatteri `mean1' 2004 `mean1' 2007, recast(line) ///
|| scatteri `mean2' 2008 `mean2' 2012, recast(line) ///
ytitle(Egg production (millions)) xtitle("") xla(2000(5)2010 2013) xtic(2001/2012) ///
scheme(s2color) yla(, ang(h)) ///
legend(order(2 "2004-07 mean `text1' m" 3 "2008-12 mean `text2' m") pos(11) ring(0) col(1))