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: averaging previous observations in panel data with missing observations


From   Mike McDonald <[email protected]>
To   [email protected]
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index