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, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Trouble plotting connected line with averages

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


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:


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 ;
    (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")
    legend(label (2 "5-Year Average") row(2) pos(6)
    name(international, replace)

#delimit cr

Thank you,
Peggy Fan
*   For searches and help try:

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