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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: Re: Loop for creating a sum of previous observations in an unbalanced panal data set


From   Christopher Baum <kit.baum@bc.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Re: Loop for creating a sum of previous observations in an unbalanced panal data set
Date   Sat, 18 Sep 2010 10:31:26 -0400

<>
On Sep 18, 2010, at 2:33 AM, Kaspar wrote:

> I have an unbalanced panel dataset with about 50 Variables and 30000
> observations between 2003 - 2010 in long format.
> I need to create a running rum variable"3m_sum_variable" which
> aggregates a certain variable (lets call it) "value" 3 months into the
> past. In other words, the variable "3m_sum_variable" should be the sum
> of all "value" variables which occurred in the last 3 months relative
> (and including) to the current observation.
> 
> I think I might create such a variable fairly easy with reshaping.
> However, since I have about 50 Variable I would rather work with my
> long format and create a loop which "goes back 3 months" into the past
> and aggregates the previous "value" variables. Does anybody know of a
> loop that can do this efficiently for an unbalanced panel datatset?

If the panel is unbalanced, but there are no internal gaps in the time series, you should be able to use Cox and Baum's mvsumm:

ssc desc mvsumm

Kit

Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
                              An Introduction to Stata Programming  |   http://www.stata-press.com/books/isp.html
   An Introduction to Modern Econometrics Using Stata  |   http://www.stata-press.com/books/imeus.html


*
*   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