Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: How to vertically align graphs with Stata 12 ? |

Date |
Mon, 13 Feb 2012 08:37:20 +0000 |

Thanks. That is now clear. The easiest way to solve this that I know is to insist on -yla(, ang(v))- in both graphs. Then you can also add -fysize()- for both graphs and -xsc(off)- for the first as below. Tune -fysize()- to choice. clear set obs 200 egen week = seq(), to(100) block(2) egen type = seq(), to(2) gen DUM = runiform() gen Y = exp(rnormal(1,1)) line DUM week, scheme(lean1) name(choice, replace) sort yla(, ang(v)) xsc(off) fysize(45) twoway (line Y week if type==1,sort lcolor(black)) /// (line Y week if type==2,sort lcolor(red)) , /// scheme(lean1) name(graph, replace) legend(off) yla(, ang(v)) fysize(55) graph combine choice graph, cols(1) xcommon Nick On Sun, Feb 12, 2012 at 4:49 PM, Francesco <cariboupad@gmx.fr> wrote: > I have a panel database that I aggregate using the -collapse function. > First of all, I generate a dummy variable that I would like to study (DUM) > > - gen DUM=variable_of_interest==1 > > then I collapse the database by week and type of individuals (2 types, > identified by the dummy variable TYPE) > > -collapse (count) count_Y=Y /// > (mean) mean_Y=Y /// > (mean) mean_DUM=DUM /// > , by(week type) fast > > I create the first graph, which requires at leat 10 datapoints per > week and plots the evolution of the DUM's proportion for type 1 > individuals > > - line mean_DUM week if count_Y>10&`TYPE'==1 , scheme(lean1) > name(choice, replace) sort > > And I would like to plot it against the output Y for the two different types : > > -twoway (line mean_Y week if count_Y>10&`TYPE'==1,sort lcolor(black)) > (line mean_Y week if count_Y>10&`TYPE'==0,sort lcolor(red)) , > scheme(lean1) name(graph, replace) legend(off) > > Therefore I type : > -graph combine choice graph, cols(1) xcommon > > The graph that I obtain is exactly what I want (one graph per row)... > except for the (important) fact that there is a slight lag in the > alignment of the x-axis due to (I guess) the difference in length of > digits between DUM (0.2 for example) and Y (0.002 for example) ... > On 12 February 2012 15:13, Nick Cox <njcoxstata@gmail.com> wrote: >> The thread you cite from 2003 concerns graphs from -graph hbar-. In >> that case the graphs are rather different from yours given Stata's use >> of categorical axes. >> >> As you have results from -line-, meaning -twoway line-, I would expect >> -graph combine- to give good results but it may require use of the >> -xcommon- option. >> >> >> On Sun, Feb 12, 2012 at 12:15 PM, Francesco <cariboupad@gmx.fr> wrote: >> >>> I created 3 (sub)graphs using the -line command, where the x-axis >>> represents dates (months, years, etc), and I would like to align them >>> vertically. >>> That is obtaining one single graphical output that displays one >>> (sub)graph per row and with the following important feature : if you >>> draw an imaginary vertical line from a particular date of any graph >>> you should cut the x-axis of the other graphs at the same date... >>> >>> I tried with the -graph combine option, but it does not work properly >>> : there is a slight time lag probably due to y-axis labels... so the >>> graphs are not perfectly aligned.. >>> Also I found a thread which basically concludes that it is not obvious >>> to do this with Stata in a slightly different context : >>> (http://www.stata.com/statalist/archive/2003-12/msg00329.html) >>> >>> However this post was made in ... 2003 ! I am sure that some >>> improvements have been introduced since... * * 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/

**Follow-Ups**:**Re: st: How to vertically align graphs with Stata 12 ?***From:*Francesco <cariboupad@gmx.fr>

**References**:**st: How to vertically align graphs with Stata 12 ?***From:*Francesco <cariboupad@gmx.fr>

**Re: st: How to vertically align graphs with Stata 12 ?***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: How to vertically align graphs with Stata 12 ?***From:*Francesco <cariboupad@gmx.fr>

- Prev by Date:
**Re: st: gologit2 and mlogit coefficients do not agree** - Next by Date:
**Re: st: Zeros and measures of inequality or concentration** - Previous by thread:
**Re: st: How to vertically align graphs with Stata 12 ?** - Next by thread:
**Re: st: How to vertically align graphs with Stata 12 ?** - Index(es):