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: Trouble plotting connected line with averages


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Trouble plotting connected line with averages
Date   Fri, 26 Apr 2013 08:14:11 +0100

Clearly I do not have your data and cannot play with it. So, I used an
example that can be replicated by any one. I don't understand why you
dismiss the example, because plotting separately for each company in
that dataset seems parallel to your wanting to plot separately for
each textbook in your dataset. (In your first posting you said nothing
about textbooks, just mentioned a variable -year_bin-, but wanting
subsets is common to both questions.)

So I cannot add constructively to my earlier post. Perhaps someone
else can work out what you mean. Or you might be able

to find an example of the kind of diagram you want on the internet
and give us an accessible URL

or

to post a minimal dataset which is enough to use your original code

or

to post the graph you have already at some URL

Statalist does not allow attachments.
Nick
[email protected]


On 25 April 2013 23:22, Peggy Fan <[email protected]> wrote:
> Thank you, Nick.
>
> I'm not sure where the "company" variable fit into all this. My
> observations are a set of textbooks and I want to look at the dependent
> variable "international" index for each of the textbook.
>
> I tried to replicate the code and still got lines connecting every dot to
> every other dot, plus another set of red lines that plot the "mean."
>
> Any ideas?
>
> Peggy
>
> ----- Original Message -----
> From: "Nick Cox" <[email protected]>
> To: [email protected]
> Sent: Tuesday, April 16, 2013 11:48:50 AM
> Subject: Re: st: Trouble plotting connected line with averages
>
> Consider
>
> webuse grunfeld
> gen year5 = 5 * floor(year/5)
> egen mean5 = mean(kstock), by(year5 company)
> twoway connected kstock year if company == 1 || line mean5 year if
> company == 1, c(J)
>
> Does that help?
>
> Nick
> [email protected]
>
>
> On 16 April 2013 19:35, Peggy Fan <[email protected]> wrote:
>> Hi,
>>
>> I'm trying to plot a graph, where the dependent variable is 5-year average of an index, and I want to plot against the same 5-year interval. I wish to plot a line that connects the data points, but when I use the connect(l) command, what I get is lines from each data point connecting to all other
>> data points (basically like a network looking kind of image). But I want a linear line. I suspect this has something to do with the year_bin and the averages, but I don't know how to solve this problem. My code is below:
>>
>> preserve
>>
>> glob width  = 5
>> cap drop year_bin
>> gen year_bin= $width*int((year)/$width)
>> cap drop tag
>> egen tag = tag(year_bin)
>>
>> egen mean_international = mean(international), by(year_bin)
>> lab var mean_international "International Index 5-Year Average"
>>
>> #delimit ;
>> twoway
>>     (scatter mean_international year_bin, mc(blue) msymbol(S) msize(small)
>> connect (l))
>>     (qfit mean_international year_bin, lc(black) range(1980 2010))
>>     (qfit mean_international year_bin, lc(black) range(1950 1980)),
>>     subtitle("International Index, 1950-2010")
>>     xtitle("Year of Publication")
>>     ytitle("Index")
>>     legend(label (2 "5-Year Average") row(2) pos(6)
>>             size(*.80))
>>     xlabel(1945[10]2011)
>>     ylabel(0[.2]0.7)
>>     xline(1980)
>>     graphregion(color(white))
>>     name(international, replace)
>>
>> ;
>> #delimit cr
>>
>> Thank you,
>> Peggy Fan
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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