Hello STATA people,
I have this data at hand:
As you can see, it is about monthly observations from 2000 to 2019 of the Unemployment and Inflation rates for a given economy.
The idea is to draw a line graph which shows the yearly evolution of both variables, with the monthly observations as ticks in each year.
When I run this code:
gen mdate = monthly(substr(Month, 1, 7), "YM")
local tickpos = ym(2000, 12) + 0.5
local ticks `tickpos'
forval y = 2000/2019 {
local labelpos = `tickpos' + 6
local labels `labels' `labelpos' "`y'"
local tickpos = ym(`y', 12) + 0.5
local ticks `ticks' `tickpos'
}
line Unemployment_Rate Inflation_Rate mdate, lc(red blue) yla(, ang(h)) ytitle(%, orient(horiz)) xla(`labels', noticks) xticks(`ticks', tlength(*3)) xtitle("") legend(ring(0) pos(11) col(1)) xsc(r(. `=ym(2025, 6)')) xli(`ticks', lc(gs12))
I get a line graph that is offset from the X axis of the years, and I do want to adjust that.
Any help please?
With many thanks!
I have this data at hand:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str7 Month float(Unemployment_Rate Inflation_Rate) "2000-01" 9.7 .3 "2000-02" 9.7 .4 "2000-03" 9.7 .4 "2000-04" 9.6 .2 "2000-05" 9.6 .2 "2000-06" 9.5 .4 "2000-07" 9.5 .2 "2000-08" 9.4 .1 "2000-09" 9.4 .6 "2000-10" 9.3 .2 "2000-11" 9.3 .3 "2000-12" 9.3 .4 "2001-01" 9.3 -.2 "2001-02" 9.2 .4 "2001-03" 9.2 .6 "2001-04" 9.3 .7 "2001-05" 9.3 .6 "2001-06" 9.3 .2 "2001-07" 9.3 -.2 "2001-08" 9.3 0 "2001-09" 9.3 .3 "2001-10" 9.4 .2 "2001-11" 9.4 0 "2001-12" 9.5 .5 "2002-01" 9.5 .2 "2002-02" 9.5 .2 "2002-03" 9.5 .5 "2002-04" 9.6 .5 "2002-05" 9.6 .2 "2002-06" 9.6 -.1 "2002-07" 9.7 -.1 "2002-08" 9.7 .1 "2002-09" 9.8 .3 "2002-10" 9.7 .3 "2002-11" 9.8 0 "2002-12" 9.8 .5 "2003-01" 9.8 .1 "2003-02" 9.8 .4 "2003-03" 9.8 .6 "2003-04" 9.8 .2 "2003-05" 9.8 -.1 "2003-06" 9.9 .1 "2003-07" 9.9 -.1 "2003-08" 9.9 .1 "2003-09" 9.9 .4 "2003-10" 9.9 .2 "2003-11" 9.9 .1 "2003-12" 10 .3 "2004-01" 10.1 -.1 "2004-02" 10 .2 "2004-03" 10.1 .6 "2004-04" 10 .5 "2004-05" 10 .4 "2004-06" 10 .1 "2004-07" 9.9 -.2 "2004-08" 9.9 .1 "2004-09" 10 .1 "2004-10" 10 .4 "2004-11" 10 -.1 "2004-12" 9.9 .3 "2005-01" 9.8 -.5 "2005-02" 9.8 .4 "2005-03" 9.8 .7 "2005-04" 9.8 .5 "2005-05" 9.8 .2 "2005-06" 9.8 .1 "2005-07" 9.7 -.1 "2005-08" 9.6 .2 "2005-09" 9.6 .5 "2005-10" 9.6 .3 "2005-11" 9.5 -.2 "2005-12" 9.4 .3 "2006-01" 9.3 -.3 "2006-02" 9.2 .3 "2006-03" 9.1 .5 "2006-04" 9 .7 "2006-05" 8.9 .3 "2006-06" 8.7 .1 "2006-07" 8.7 -.1 "2006-08" 8.6 .1 "2006-09" 8.5 0 "2006-10" 8.4 .1 "2006-11" 8.3 .1 "2006-12" 8.2 .3 "2007-01" 8 -.4 "2007-02" 7.9 .3 "2007-03" 7.8 .6 "2007-04" 7.7 .6 "2007-05" 7.6 .3 "2007-06" 7.5 .1 "2007-07" 7.5 -.2 "2007-08" 7.5 .1 "2007-09" 7.4 .4 "2007-10" 7.4 .5 "2007-11" 7.3 .6 "2007-12" 7.3 .4 "2008-01" 7.2 -.1 "2008-02" 7.1 .4 "2008-03" 7.1 .9 "2008-04" 7.1 .4 end
The idea is to draw a line graph which shows the yearly evolution of both variables, with the monthly observations as ticks in each year.
When I run this code:
gen mdate = monthly(substr(Month, 1, 7), "YM")
local tickpos = ym(2000, 12) + 0.5
local ticks `tickpos'
forval y = 2000/2019 {
local labelpos = `tickpos' + 6
local labels `labels' `labelpos' "`y'"
local tickpos = ym(`y', 12) + 0.5
local ticks `ticks' `tickpos'
}
line Unemployment_Rate Inflation_Rate mdate, lc(red blue) yla(, ang(h)) ytitle(%, orient(horiz)) xla(`labels', noticks) xticks(`ticks', tlength(*3)) xtitle("") legend(ring(0) pos(11) col(1)) xsc(r(. `=ym(2025, 6)')) xli(`ticks', lc(gs12))
I get a line graph that is offset from the X axis of the years, and I do want to adjust that.
Any help please?
With many thanks!

Comment