Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: Calculating returns between 2 dates using 2 files


From   "Hugh Colaco" <[email protected]>
To   [email protected]
Subject   Re: st: Re: Calculating returns between 2 dates using 2 files
Date   Fri, 5 May 2006 18:19:44 -0400

Thanks Michael and Austin. Both codes worked well, but I ended up
using Michael's because it ran much quicker.

Hugh


On 4/24/06, Michael Blasnik <[email protected]> wrote:
I would use the first file to calculate a running cumulative return for each
date and then merge that to each of the two dates in the other file.
Something like:

use file1
gen cumreturn=sum(ln(1+return[_n-1]))
keep date cumreturn
sort date
save cumreturns

use file2
gen date=date1
sort date
merge date using cumreturns, nokeep
drop _merge
rename cumreturn cumreturn1
replace date=date2
sort date
merge date using cumreturns, nokeep
replace cumreturn=exp(cumreturn-cumreturn1)-1
drop cumreturn1 _merge

Michael Blasnik
[email protected]


----- Original Message -----
"Hugh Colaco" <[email protected]> wrote:
> Hi Statalist,
>
> I have 2 files; one with dates and returns on each date (i.e. File 1)
> and the second, two given dates for each observation. The dates run
> from 1990 to 2004.
>
> I want to calculate "DateRet" (i.e. the return between the two dates
> in file 2) for each obs. I have approx 1000 obs. Note from the example
> that Date2 return is not considered (i.e. the last return considered
> is the date prior to Date2).
>
> Thanks,
>
> Hugh
<snip>

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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