# Re: st: Cumulative return for each firm each day

 From "Hua Pan" To statalist@hsphsun2.harvard.edu Subject Re: st: Cumulative return for each firm each day Date Thu, 12 Mar 2009 20:34:47 +0100

```Dear Martin, Austin, Antoine and Nick

Thank you sooooo much for your great help and wonderful answers. Although it’s very easy for you, but for me as a beginner, I’ve already spent a lot of time on the issue with reading books, search for special ado files, FAQ, Statalist archives… and can’t find the answer. So I come here to ask for help and all of you are so kind and give me the answer, thank you!

Austin:  thanks a lot for your help. Two methods work very well when all of the returns are available.  But I find out when one ret is missing, all of the returns behind it will be missing, even their ret are not, with the first method (because of l.cumul). With the second one all missing values of ret are treated as 0 and all of the Cret have a value, so I think the second one, that’s exactly the one of Antoine, is better. Many thanks, Antoine!

Nick, thank you for your comment, I’ll pay more attention to the legal statements later.

Martin, thank you for your always quick response and the recommend of rollreg, I’m doing exactly time series analysis and it maybe very helpful for me later.

Again thank you all!

Best Wishes

Hua

-------- Original-Nachricht --------
> Datum: Thu, 12 Mar 2009 13:37:05 -0400
> Von: Austin Nichols <austinnichols@gmail.com>
> An: statalist@hsphsun2.harvard.edu
> Betreff: Re: st: Cumulative return for each firm each day

> Hua Pan <panhua@gmx.de>:
> Here are two methods in one example (results may differ if you have
> breaks in time series or missing data):
>
>  webuse grunfeld, clear
>  g ret=invest/1500
>  bys company (year): g cumul=1+ret if _n==1
>  replace cumul=(1+ret)*l.cumul if mi(cumul)
>  replace cumul=cumul-1
>  bys company (year): g c=sum(ln(ret+1))
>  replace c=exp(c)-1
>  li year ret cumul c if company==1, noo clean
>
>
> On Thu, Mar 12, 2009 at 12:27 PM, Hua Pan <panhua@gmx.de> wrote:
> > Dear Statalisters�¼
> >
> > I want to loop over firms and days, in order to calculate cumulative
> daily return for each firm and from day 1 to day 30. That means,
> >
> > firm       day             ret        Cret
> > 1            1              x1         x1
> > 1            2              x2        (1+x1)*(1+x2)-1
> > …           …                …         …
> > 1            30             x30
> (1+x1)*(1+x2)*…(1+x30)-1
> > 2            1
> > …             …
> > 2            30
> > ..
> > firm and day have numeric format.
> >
> > I tried:
> >
> > sort firm day
> > generate Cret = 0
> > levelsof firm, local(firms)
> > levelsof day, local(days)
> > foreach f of local firms {
> > foreach d of local days {
> > gen Cret(`f’, `d’) =  (1+Cret)*(1+ret)-1  if  firm == `f' & day
> == `d'
> > replace Cret = Cret(`f’, `d’)  if firm == `f' & day >= `d'
> > drop Cret(`f’, `d’)
> > }
> > }
> >
> >
> > But it doesn’t seem to work. Have anyone idea about cumulative return
> or just cumulative sum for each firm and everyday, or just looping of this
> kind?
> >
> > Any help and suggestion would be greatly appreciated. Thank you very
> >
> > Best regards
> >
> > Hua
>
> *
> *   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/

--
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01
*
*   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/
```