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   Austin Nichols <[email protected]>
To   [email protected]
Subject   Re: st: Trouble plotting connected line with averages
Date   Fri, 26 Apr 2013 10:14:30 -0400

Peggy Fan <[email protected]>:

I suspect you need to sort on year_bin, as in the following example.

However, I don't think you are getting what you want from your qfit calls;
did you mean to constrain the estimation of those fits to the ranges specified,
or merely to graph the fits with different types of lines? Note
in the following example there is no data to estimate the later
part of the curve!

webuse grunfeld, clear
replace year=year+15
ren mvalue international
g u=uniform()
sort u
gen y=5*floor(year/5)
egen tag = tag(y)
egen m=mean(international), by(y)
lab var m "International Index 5-Year Average"
loc s sc m y, mc(blue) ms(S) msize(small) c(l)
loc q qfit m y, lc(black) ra(1980 2010)
loc r qfit m y, lc(black) ra(1950 1980)
loc o subtitle("International Index, 1950-2010")
loc o `o' xtitle("Year of Publication")
loc o `o' ytitle("Index")
loc o `o' legend(label (2 "5-Year Average")
loc o `o' row(2) pos(6) size(*.80))
loc o `o' xlabel(1945[10]2011)
loc o `o' ylabel(0[.2]0.7)
loc o `o' xline(1980)
loc o `o' graphr(color(white))
tw (`s') (`q') (`r'), `o' name(i1, replace)
sort y
tw (`s') (`q') (`r'), `o' name(i2, replace)


On Thu, Apr 25, 2013 at 6:22 PM, 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)
*
*   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