Date: Thu, 2 Jul 2009 06:30:38 -0700
Reply-To: smolkatz <smolkatz@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: smolkatz <smolkatz@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: how to lag in panel
Content-Type: text/plain; charset=ISO-8859-1
On Jul 2, 2:39 pm, ilann...@GMAIL.COM (Liang Xu) wrote:
> Hi,guys. I have an unbalanced panel data, and I need to lag some variables.
>
> name time value name time value
> a 1 20 a 1 .
> a 2 30 a 2 20
> a 3 40 a 3 30
> b 1 22 to b 1 .
> b 2 33 b 2 22
> b 3 44 b 3 33
>
> It looks that the example above. My problem is how to deal with the value of
> b at time 1 when I lag b once?
> And if I want to lag b twice, how can I do it?
> Thanks!
Hi,
if you want to lag every name only once as you show in then example
than this could be the answer:
data a;
input name $ time value;
cards;
a 1 20
a 2 30
a 3 40
b 1 22
b 2 33
b 3 44
;
proc sort data=a;
by name time;
run;
data b;
set a;
by name;
value=lag(value);
if first.name then value=.;
run;
Alexandra
|