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


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

st: averaging previous observations in panel data with missing observations


From   Mike McDonald <mimcdonald03@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: averaging previous observations in panel data with missing observations
Date   Mon, 23 Jul 2012 22:20:22 -0400

Hi Statalisters:

I have panel data across countries for each year 1960-2010. For each
country/year, I want to create a variable, y_avg, that is the average
of that variable over the past 10 years. I know I can do this manually
like this:

gen y_avg = (L1.x + L2.x + ... + L10.x) / 10

The problem is that there is missing data all over the place, so this
breaks down for any 10-year period with missing observations.

I have seen some other suggestions in searching the statalist archive
-- for instance using egen with filter() -- but it is not clear to me
that any of these ideas overcome the missing data problem.

Can anyone suggest an easy way to accomplish what I want, ignoring
missing observations in each average?

Thanks!

Mike McDonald
University of Maryland
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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