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 (July 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 5 Jul 2006 06:30:38 -0400
Reply-To:     Jim Groeneveld <jim2stat@YAHOO.CO.UK>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jim Groeneveld <jim2stat@YAHOO.CO.UK>
Subject:      Re: lag, retain etc
Comments: To: Dirk Nachbar <Dirk.Nachbar@DWP.GSI.GOV.UK>

Hi Dirk,

Well, for the first record (1978) the LAG function always returns a missing value as there is no previous record. Next, the lag function may not do what you want it to do: for example you change Pay01 based on its lag. Then for the next record you want to do the same and expect the LAG of Pay01 to be the Pay01 value as calculated for the previous record. AND THAT IS NOT TRUE! You get the Pay01 value as it is in the dataset! The RETAIN option is not an option here too as you still get the values from the dataset (and these are automatically retained).

So for all those lagged variables that you want to calculate you have to use new variables, not yet in the dataset. So, for example just for Pay01 (this is just the minimal idea):

IF (_N_ EQ 1) NewPay01 = Pay01; NewPay01 = ....... LAG(NewPay01) .........; Pay01 = NewPay01;

So you only use the very first value of Pay01 in your dataset and no more.

Regards - Jim. -- Jim Groeneveld, Netherlands Statistician, SAS consultant home.hccnet.nl/jim.groeneveld

On Wed, 5 Jul 2006 10:55:07 +0100, Dirk Nachbar <Dirk.Nachbar@DWP.GSI.GOV.UK> wrote:

>All > >I want to predict past values by a reversed AR model. For that I sorted my data >set by id descending taxyear. Unfortunately the lag function doesn't do what I >thought it would. I also tried retain without success. > >cl1wks and cl2wks are populated for 1978-2003, but predictions before 1978 >become missing. > >Help is appreciated. > >data &out /*(drop=cl1wks_1 cl2wks_1 totqualyears_1 pay01_1)*/; > set home.privpa2; > cl1wks_1=lag(cl1wks); > cl2wks_1=lag(cl2wks); > totqualyears_1=lag(totqualyears); > pay01_1=lag(pay01); > if taxyear<1985 then do; > cl1wks=round(5.387133+.3824018*cl1wks_1,1); > cl2wks=round(42.16179 +.1938874*cl2wks_1 ,1); > totqualyears=max(0,totqualyears_1-(cl1wks+cl2wks>0)); > end; > if taxyear<1999 then do; > pay01=exp(6.107534+.03925 *sum(0,pay01_1)+)*(cl1wks>0); > end; > pay201=exp(6.86589+0.09286*age-0.00108*age**2+0.77794*male)* (cl2wks>0); >run; > >Dirk Nachbar >Assistant Economist >Pensim2 >Department for Work and Pensions >Level 4, The Adelphi >1-11 John Adam St >WC2N 6HT London >020 796 28531 >********************************************************************** >This document is strictly confidential and is intended only for use by the addressee. >If you are not the intended recipient, any disclosure, copying, distribution or other >action taken in reliance of the information contained in this e-mail is strictly prohibited. >Any views expressed by the sender of this message are not necessarily those of the Department >for Work and Pensions. >If you have received this transmission in error, please use the reply function to tell us >and then permanently delete what you have received. >Please note: Incoming and outgoing e-mail messages are routinely monitored for compliance >with our policy on the use of electronic communications. >********************************************************************** > > > >The original of this email was scanned for viruses by Government Secure Intranet (GSi) virus scanning service supplied exclusively by Cable & Wireless in partnership with MessageLabs. >On leaving the GSI this email was certified virus free. >The MessageLabs Anti Virus Service is the first managed service to achieve the CSIA Claims Tested Mark (CCTM Certificate Number 2006/04/0007), the UK Government quality mark initiative for information security products and services. For more information about this please visit www.cctmark.gov.uk


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