Statalist


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

st: AW: Cumulative return for each firm each day


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: Cumulative return for each firm each day
Date   Thu, 12 Mar 2009 18:10:09 +0100

<> 


Hua, 

you may profit from -ssc d rollreg- and Baum (2006), chap. 9.5. (http://www.stata-press.com/books/imeus.html)

Also note http://www.stata.com/statalist/archive/2005-06/msg00619.html




HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Hua Pan
Gesendet: Donnerstag, 12. März 2009 17:27
An: [email protected]
Betreff: st: Cumulative return for each firm each day

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 much in advance for your time.

Best regards

Hua






-- 
Nur bis 16.03.! DSL-Komplettanschluss inkl. WLAN-Modem für nur 
17,95 ¿/mtl. + 1 Monat gratis!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a
*
*   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/


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index