Creating variable based on lags

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Open this post in threaded view
Report Content as Inappropriate

Creating variable based on lags

Am Gut
Good Afternoon Everyone,

I have a series of returns are was hoping that someone could help me create
a variable based on a pre-specified set of lagged observations. For
example, I would want to sum up the last 25 returns to make a new return
column. I would also like to weight the returns by a factor of 0.25^i with
i being the lag number. I am intuitively thinking a for loop but can not
rationalize internally how to write this. I am trying to make a variable
like below:

newreturn = return(-1)*0.25^1 + return(-2)*0.25^2 + .... return(-25)*0.25^25

And obviously I would like to apply this to all new observations past the
25th observatios to the end of my dataset. I hope this is clear as I know
the solution must be relatively simple. I hope to hear from you guys.


Am Gut

        [[alternative HTML version deleted]]

[hidden email] mailing list
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.