Date: Fri, 29 Dec 2006 11:08:59 -0500
Reply-To: Ken Borowiak <EvilPettingZoo97@AOL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ken Borowiak <EvilPettingZoo97@AOL.COM>
Subject: Re: Lag or array question
On Fri, 29 Dec 2006 10:20:50 -0500, Peter Flom <Flom@NDRI.ORG> wrote:
>Thanks!
>
>That worked perfectly
>
>Thanks to Wensui, as well.
>
>Peter
>
>>>> <Nathaniel_Wooding@Dom.com> 12/29/2006 10:14 am >>>
>Oops
>
>Forgot to take into the change between MSAs
>
>Nat
>
>DATA A;
>INPUT MSA Year Unemp;
>CARDS;
>1 1990 5.1
>1 1991 6.
>1 1992 7
>1 1993 9
>2 1990 1
>2 1991 2
>2 1992 55
>Data b;
> set a;
> by msa;
> if first.msa then count=0;
> count+1;
>
> lagUnemp=lag2(unemp);
> if count le 2 then lagUnemp=.;
>
>proc print;
>run;
>
>
>
> Peter Flom
> <Flom@NDRI.ORG>
> Sent by: "SAS(r) To
> Discussion" SAS-L@LISTSERV.UGA.EDU
> <SAS-L@LISTSERV.U cc
> GA.EDU>
> Subject
> Lag or array question
> 12/29/2006 10:01
> AM
>
>
> Please respond to
> Peter Flom
> <Flom@NDRI.ORG>
>
>
>Hello
>
>I have a data set that has (among other things) the following structure
>
>MSA Year Unemp
>1 1990 5.1
>1 1991 6.0
>
>.. (through 2002)
>2 1990 4.1
>2 1991 4.2
>
>.... (for 96 MSAs)
>
>I would like to create a variable of lagged unemployment by 2 years. So,
>lagunep for 1992 would be unemp for 1990, for each MSA.
>
>I'm sure this is easy for the data step gurus, but I can't see how best to
>do it.
>
>(for context, I will then be using lagunemp in a multilevel model using
>other variables in the data set.
>
>
>TIA and HNY
>
>Peter
>
>
>
>Peter L. Flom, PhD
In case you are interested in an SQL solution ...
proc sql ;
select T1.*,
T2.Unemp as LagUnemp
from A T1
left join
A T2
on T1.MSA=T2.MSA &
T1.Year-T2.Year=2 ;
quit ;
HTH,
Ken
|