09-22-2014 07:07 PM
New here so I'd really appreciate any help I can get.
So I have loan data which is already sorted by lender, I.D. and date_taken. First, for all count=1 the newest date(created var) = date_paid. Then I want the code to look at the lagged value(of the new variable(newest date)) to see if it is greater than the current date paid on the loan. If it is, I want the larger date in the new variable's observation. This new variable's value should then be looked at to calculate the next observations value. Below is an example of what IT SHOULD LOOK LIKE and the Right most column is what I actually get. Followed by the current code I am running.
|Lender||I.D||Count||Date Loan Taken||Date Paid||Newest Date(correct)||Newest Date(actual)|
by lender ID;
if first.Newest_Date then Newest_Date= Date_Paid;
if Date_Paid> lag(Newest_Date) then Newest_Date= Date_Paid;
else Newest_Date= lag(Newest_Date);
Now I know that the lag function won't work here except for the second observation of a group. So I am curious if there is a two step process I can do or something else I haven't thought of to look at the subsequent lag values when creating a new value.