Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: [Graphics] how to set the length of an axis?


From   Ulrich Kohler <kohler@wzb.eu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: [Graphics] how to set the length of an axis?
Date   Mon, 23 Mar 2009 09:39:05 +0100

I thing you did. I have one comment and one question.

Comment: A nice trick to label the years for which you have data is

. levelsof year, local(lab)
. twoway rbar lower upper wageclass, xlabel(`lab')

Question: Adjusting the bar-width with 

. levelsof wageclass, local(K)
. local width  = (`:word 2 of `K'' - `:word 1 of `K'')
. twoway    
    || rbar lower upper wageclass,  barwidth(`width') horizontal  

does not work sufficiently for me. On my screen (Stata 10.1 for Linux), the bars overlap, 
(although I think they shouldn't). In my proposal I have therefore used

. local width  = (`:word 2 of `K'' - `:word 1 of `K'') * .95

to scale the bar width somewhat further down. Wasn't that necessary under Windows?

Uli
 

Am Samstag, den 21.03.2009, 17:18 +0100 schrieb Antoine Terracol:
> Thanks to Ulrich, Nick and all the others who answered my question, I 
> think I met the challenge...
> 
> 
> Antoine
> 
> 
> For anyone interrested, here is the code:
> 
> /*----------------------------*/
> 
> clear
> set scheme s2mono
> webuse nlswork.dta, clear
> g wage=exp(ln_wage)
> su wage, de
> drop if wage>r(p99)
> gen t=(year)
> g ti=t
> g ti2=t^2
> g ti3=t^3
> qreg wage ti ti2 ti3
> est store med
> qreg wage ti ti2 ti3 , quantile(.95)
> est store p95
> qreg wage ti ti2 ti3 , quantile(.05)
> est store p5
> 
> drop ti ti2 ti3
> g ti=t+runiform()
> g ti2=ti^2
> g ti3=ti^3
> 
> est restore med
> predict med
> predict resmed, resid
> 
> est restore p95
> predict q95
> predict resq95, resid
> 
> est restore p5
> predict q5
> predict resq5, resid
> 
> 
> by t, sort: egen pct25 = pctile(resmed), p(25)
> by t, sort: egen pct50 = pctile(resmed), p(50)
> by t, sort: egen pct75 = pctile(resmed), p(75)
> egen ufence = adju(resmed), by(t)
> egen lfence = adjl(resmed), by(t)
> 
> reg resq5 ti ti2 ti3
> predict resq5hat
> 
> reg resq95 ti ti2 ti3
> predict resq95hat
> 
> 
> sum wage, meanonly
> gen wageclass = autocode(wage,32,r(min),r(max))
> by t wageclass, sort: gen wageperc = _N/r(N)
> 
> // rescale wageperc
> sum wageperc, meanonly
> replace wageperc = wageperc/r(max) * .90
> 
> gen lower = t
> gen upper = t + wageperc
> 
> preserve
> bysort t wageclass : keep if runiform()<0.05 | _n==1
> 
> levelsof wageclass, local(K)
> local width  = (`:word 2 of `K'' - `:word 1 of `K'')
> twoway    ///
>    || rbar lower upper wageclass,  graphregion(color(white))     ///
>    fcolor(gs15)  barwidth(`width') horizontal  xlabel(68(5)88)   ///
>    || line med q95 q5 ti, sort lpattern(solid..) lcolor(black..) ///
> 	legend(off) xtitle(year)  saving(b, replace) nodraw
> 
> 
> twoway ///
> 	rspike ufence pct75 t , color(black) ///
> || rspike lfence pct25 t , color(black) 	///
> || rcap ufence ufence t , color(black) ///
> || rcap lfence lfence t , color(black) ///
> || rbar pct25 pct50 t, barwidth(.5) fcolor(gs15) lcolor(black) ///
> || rbar pct50 pct75 t, barwidth(.5) fcolor(gs15) lcolor(black) ///
> || line resq5hat resq95hat ti , sort lpattern(solid..) ///
>   lcolor(black..) graphregion(color(white)) ///
> legend(off) xlabel(68(5)88 , nolabel notick) ///
> fysize(20) saving(b2, replace) nodraw
> 
> 
> graph combine b2.gph b.gph, graphregion(color(white)) col(1)
> restore
> 
> /*----------------------------*/
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
-- 
kohler@wzb.eu
030 25491-361

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index