Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

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

From   Francesco <>
Subject   Re: st: How to vertically align graphs with Stata 12 ?
Date   Sun, 12 Feb 2012 17:49:45 +0100

Dear Nick,

You are right, thanks for your remark

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

- 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) ...

What do you think ?

Many, many thanks in advance,

On 12 February 2012 15:13, Nick Cox <> 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.
> In any case you don't give here _any_ exact syntax  that would allow
> detailed comment on what you did. You already should have read this
> advice at
> "Say exactly what you typed and exactly what Stata typed (or did) in
> response. N.B. exactly! If you can, reproduce the error with one of
> Stata's provided datasets or a simple concocted dataset that you
> include in your posting."
> Please follow it.
> Nick
> On Sun, Feb 12, 2012 at 12:15 PM, Francesco <> 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 :
>> (
>> However this post was made in ... 2003 ! I am sure that some
>> improvements have been introduced since...
> *
> *   For searches and help try:
> *
> *
> *

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index