LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2011, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 2 Aug 2011 19:59:56 -0500
Reply-To:     "Data _null_;" <iebupdte@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Data _null_;" <iebupdte@GMAIL.COM>
Subject:      Re: Progressive calculation of a variable using its own lagged
              values
Comments: To: Monica <WBS.PhD@gmail.com>
In-Reply-To:  <201108030004.p72AqFMN015978@wasabi.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1

RETAIN EWMA as in this example. Please check formula carefully.

data ewma; input Date:mmddyy. Ret Std Lambda; if _n_ eq 1 then ewma = std; else ewma = sqrt(lambda*ewma**2 + ewma + (1-lambda)*ret**2); retain ewma; format date mmddyy.; cards; 02/01/00 0.12 0.1 0.94 03/01/00 0.11 0.2 0.94 04/01/00 0.04 0.3 0.94 05/01/00 0.10 0.4 0.94 06/01/00 0.05 0.5 0.94 07/01/00 0.15 0.6 0.94 ;;;; run; proc print; run; On Tue, Aug 2, 2011 at 7:04 PM, Monica <WBS.PhD@gmail.com> wrote: > Dear all, > I have an apparently simple question which I cannot sort out by myself. > Let's say I have the following dataset: > Date (t) Ret Std Ewma Lambda > 02/01/00 0.12 0.1 0.94 > 03/01/00 0.11 0.2 0.94 > 04/01/00 0.04 0.3 0.94 > 05/01/00 0.10 0.4 0.94 > 06/01/00 0.05 0.5 0.94 > 07/01/00 0.15 0.6 0.94 > > > I need to construct the Ewma variable in the following way: > for first observation (t=02/01/00) Ewma(t)=Std(t)=0.1 > for all other obsevations t: > Emwa(t)=sqrt(Lambda*Emwa(t-1)*Emwa(t-1)+(1-Lambda)*Ret(t)*Ret(t)) > Where Emwa(t-1) is simply the past value of Emwa. > Could you suggest an efficient way to do it? > Many thanks for your help, > Monica >


Back to: Top of message | Previous page | Main SAS-L page