notes smoothing -running means and lines

notes smoothing -running means and lines - Eco 572 Research...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Eco 572: Research methods in Demography Smoothing: Running Means and Lines We will work with data from the Colombia WFS Household Survey, conducted in 1975-76. I tabulated the age distribution of all household members and saved it in an ascci file, which we now read and plot: . infile age pop using /// > http://data.princeton.edu/eco572/datasets/cohhpop.dat (99 observations read) . line pop age , /// > title(Colombia 1975-76) subtitle(WFS Household Survey) /// > ytitle(population) . graph export cohhpop.png, replace (file cohhpop.png written in PNG format) As you can see, the distribution looks somewhat less smooth than the data from the Philippines we studied earlier. Can you compute the Myers index for this distribution? Running Means The simplest way to smooth a scatterplot is to use moving averages, also know as running means. We (1 of 7) [2/12/2008 10:25:58 AM] http://data.princeton.edu/eco572/smoothing1.html
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Eco 572: Research methods in Demography can easily compute a moving average with a window of three, where for each observation we consider the neighbors immediately above and below: . gen ma3 = ( pop[_n-1] + pop[_n] + pop[_n+1] )/3 (2 missing values generated) . replace ma3 = (pop[1]+pop[2])/2 in 1 (1 real change made) . replace ma3 = (pop[_N-1] + pop[_N])/2 in -1 (1 real change made) The first and last observations have only one neighbor each, and Stata rightly returns a missing value, which we replace by the average of just two. There is, of course, an easier way. The lowess command can compute running means if you specify the options mean and noweight . The window is specified as a proportion of the data via an option called bwidth , which is short for bandwidth. To reproduce our result we need to use 0.03 or 3% of the data: . lowess pop age, mean noweight bwidth(0.03) /// > gen(rm3) name(rm3) title(" ") First let us list a couple of cases to verify that lowess and us are doing the same thing: . list age ma3 rm3 in 1/4 +-------------------+ | age ma3 rm3 | |-------------------| 1. |
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern