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]

st: Trouble plotting connected line with averages


From   Peggy Fan <[email protected]>
To   [email protected]
Subject   st: Trouble plotting connected line with averages
Date   Tue, 16 Apr 2013 11:35:11 -0700 (PDT)

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/


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