Bookmark and Share

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


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

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


From   Francesco <[email protected]>
To   [email protected]
Subject   Re: st: How to vertically align graphs with Stata 12 ?
Date   Mon, 13 Feb 2012 10:43:42 +0100

Many thanks Nick,

Your -yla(, ang(v)) idea works perfectly!

Thanks again,
Best,



On 13 February 2012 09:37, Nick Cox <[email protected]> wrote:
> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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/

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index