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   Peggy Fan <[email protected]>
To   [email protected]
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" <[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/


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