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]

From |
Nick Cox <n.j.cox@durham.ac.uk> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

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

Date |
Tue, 21 Sep 2010 11:14:00 +0100 |

I don't think there is any issue here. You never said that your data _were_ equally spaced. Yet many people will assume equal spacing unless the opposite is made clear. Thus, some suggestions may not apply. In particular, Kit Baum suggested -mvsumm-, which tacitly does assume equal spacing. It's an old story. A questioner is the most likely person to lose out if the problem described is not exactly the real problem. Nick n.j.cox@durham.ac.uk Kaspar Dardas Thanks Eric, Kit and Nick, exactly, my data is not equally spaced. Nick, does the definition of an unbalanced panel data set exclude not equally spaced observations? If yes, my apologies for being incorrect/unclear. 2010/9/20 Nick Cox <n.j.cox@durham.ac.uk>: > Eric Booth and Kit Baum made good suggestions. > > It's worth mentioning that the sum of recent values can often be evaluated as the difference between two cumulative sums. That is, > > Sum of recent values = Cumulative sum to present - Cumulative sum evaluated earlier > > This can make a loop quite unnecessary, even with panel data. Use -sum()- to create cumulative sums. > > This does require equally spaced data. Kaspar says his panel is unbalanced, but from his earlier posts, I also suspect that he does not have equal spacing. > Kaspar Dardas > ============= > > 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? * * 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/

**References**:**st: Loop for creating a sum of previous observations in an unbalanced panal data set***From:*Kaspar Dardas <kaspar.dardas@students.ebs.edu>

**st: RE: Loop for creating a sum of previous observations in an unbalanced panal data set***From:*Nick Cox <n.j.cox@durham.ac.uk>

**Re: st: RE: Loop for creating a sum of previous observations in an unbalanced panal data set***From:*Kaspar Dardas <kaspar.dardas@students.ebs.edu>

- Prev by Date:
**st: RE: Bug in comment - and comment on comment** - Next by Date:
**st: RE: RE: Bug in comment - and comment on comment** - Previous by thread:
**Re: st: RE: Loop for creating a sum of previous observations in an unbalanced panal data set** - Next by thread:
**st: a loop error of -foreach-** - Index(es):