07-31-2013 11:04 AM
I hava data organized as a panel data:
The data in this exempel consists of two individuals, five years, income for each year and the lag(income) that I created by the following data step:
by personID year;
if first.PersonID then do;
I am content with most of the results except för the Lag_income för PersonID nr 2 on year 2007 (value 500 bold). I have actually no information in the data about the income between 2001 and 2007 which I would like SAS to concider by giving the Lag(income) a missing value in stead of 500. If I use STATA it would work that way, but I can't find the way to tix it in SAS. Thanks for any tip!
07-31-2013 11:26 AM
08-01-2013 04:02 AM
Thank you Haikuo and ballardw, I tried your syntax but my SAS wont recognize the funcion ifn. In my real panel data I have to lag more then one variable.
Thans any way
08-01-2013 04:08 AM
This should work on older versions of SAS ;
by personID year;
Dif_Year = DIF (Year) ;
if first.PersonID then Lag_income=.;
Else if Dif_Year > 1 then Lag_income=.;
08-01-2013 09:05 AM
Thank you Richard!
I tried somthing close to your suggestion and it worked well:
by personID Year;
if first PersonID or year-lag(year)>1 then do;
08-01-2013 09:17 AM
dif (year) = year - lag(year)
do; <statement>; end; is redundant use of do
Be careful with lag() and dif() used in IF clauses - yours seems OK but the following can be a problem
if <condition> then X = lag(Y) ;
Its because the lag function needs to be evaluated in the record before <condition> is true, so there is a retained lagged value to be used in the rest of the statement.
07-05-2014 12:44 AM
Does ifn command work only in case we are creating lag for one variable?
I was looking at my results and realized that the same does not work while creating lags for multiple variables.
However, I had not known about this ifn function; it is a pretty neat one!