This looks a bit like the min distance problem from a few days ago,
minus the lat/lon, and every other aspect of the problem.
In other words: You could do this by looping over the obs in File 2.
use file2
gen double DateReturn=.
gen obs=_n
* just to emphasize sort order matters
forv i=1/`=_N' {
local start=Date1[`i']
local end=Date2[`i']
preserve
use file1, clear
gen double gret=ln(1+Ret)
keep if Date>=`start' & Date<`end'
gen double tret=sum(gret)
scalar lnret=tret[_N]
restore
replace DateRet=exp(lnret)-1 in `i'
}
All untested, of course.
On 4/24/06, 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
>
>
>
> File1
>
> Date Return
> 1/2/1990 0.003
> 1/3/1990 0.006
> 1/4/1990 -0.004
> 1/5/1990 0.001
> 1/8/1990 0.002
> 1/9/1990 -0.001
> 1/10/1990 -0.005
> 1/11/1990 0.002
> 1/12/1990 -0.015
> 1/15/1990 -0.005
> 1/16/1990 -0.001
> 1/17/1990 0.001
> 1/18/1990 -0.003
> 1/19/1990 0.005
> 1/22/1990 -0.011
> 1/23/1990 -0.002
> 1/24/1990 -0.011
> 1/25/1990 -0.001
> 1/26/1990 -0.005
> 1/29/1990 -0.006
> 1/30/1990 -0.011
> 1/31/1990 0.007
> 2/1/1990 0.003
> 2/2/1990 0.007
> 2/5/1990 0.004
> 2/6/1990 0.001
> 2/7/1990 0.006
> 2/8/1990 0.002
> 2/9/1990 0.004
>
>
>
>
> File2
>
> Obs Date1 Date2 DateRet
> 1 1/31/1990 2/2/1990 (1+0.007)*(1+0.003)-1
> 2 1/3/1990 1/8/1990 (1+0.006)*(1-0.004)*(1+0.001)-1
>
> *
> * 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/