| 
 |  | ||||
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: Calculating returns between 2 dates using 2 files
From 
 
"Michael Blasnik" <[email protected]> 
To 
 
<[email protected]> 
Subject 
 
st: Re: Calculating returns between 2 dates using 2 files 
Date 
 
Mon, 24 Apr 2006 18:46:42 -0400 
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:
<snip> 
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
*
*   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–2025 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |