Bookmark and Share

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]

Re: st: Trouble plotting connected line with averages


From   Peggy Fan <pfan@stanford.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Trouble plotting connected line with averages
Date   Thu, 25 Apr 2013 15:22:41 -0700 (PDT)

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" <njcoxstata@gmail.com>
To: statalist@hsphsun2.harvard.edu
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
njcoxstata@gmail.com


On 16 April 2013 19:35, Peggy Fan <pfan@stanford.edu> 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/


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