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 |
Tirthankar Chakravarty <tirthankar.chakravarty@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: counting observations |

Date |
Wed, 29 Dec 2010 16:58:30 -0800 |

One strategy is to -collapse-, -tssmooth- and -merge- back in. You will need to install Nikos Askitas's -stockquote- from SSC for this example: ********************************************* clear* stockquote ^GDAXI, fm(1) fd(2) fy(2000) lm(03) ld(4) ly(2008) frequency(d) g datef = date(date, "YMD") format datef %td g monthf = month(datef) g yearf = year(datef) tempfile colldata preserve collapse close, by(monthf yearf) generate ymdate = ym(yearf, monthf) tsset ymdate tssmooth ma smclose = close, window(3) save `colldata', replace restore merge m:1 monthf yearf using `colldata', gen(smmerge) tab smmerge ********************************************* T On Wed, Dec 29, 2010 at 4:32 PM, Jurgen Sidgman <sidgman@uwm.edu> wrote: > Hi, > > I have a dataset that has observations for each day of many months. What I need to do is: for each month I need to add all observations for each of the previous 3 months. For example, for january I need to add all observations from October to December from the previous year. Next, for february I need to add all observations from November to January and so on. What I have been doing so far is calculating the cumulative value for each month as follows: > > . sort obsdate > . egen count_obs = count(obsdate) if year(obsdate) == 2004 & month(obsdate) <= 3 (this is for the first time I perform the calculation) > > From the next time on I do: > . egen count_obs1 = count(obsdate) if year(obsdate) == 2004 & month(obsdate) <= 4 & month(obsdate) > 1 (and so on) > > When I finish all calculations I plan on copy the final result for each calculation to the appropriate month. > > My question is: does anyone have a better idea on how to do this? Maybe on a single column. It seems pretty simple but it looks like there should be a better way of doing this given the fact that on a single year I have to repeat the calculation 12 times. On a 10 year period I would have to repeat it 120 times. A do file could do it but I still would have to have 120 times the calculation. > > Thanks > > Jurgen > > > > > * > * 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/ > -- To every ω-consistent recursive class κ of formulae there correspond recursive class signs r, such that neither v Gen r nor Neg(v Gen r) belongs to Flg(κ) (where v is the free variable of r). * * 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: counting observations***From:*Jurgen Sidgman <sidgman@uwm.edu>

- Prev by Date:
**Re: Re: Re: st: 'margin' and marg. effects of second-order polynomials** - Next by Date:
**st:Creating a variable from overlapping intervals** - Previous by thread:
**st: counting observations** - Next by thread:
**st: RE: counting observations** - Index(es):