You cant use LAG within an IF statement, it won’t work as expected because it’s a queue. You need to add a counter, as I mentioned. Use the enumerate to create the new variable and then if COUNTER>1 then calculate MoM and if counter>12 then YoY changes. Untested: If first.roll_number then counter=0; Counter=1; Lag_Month = lag1(fnl_price); Lag_Year = lag12(fnl_price); If counter>1 then MoM = (fnl_price/lag_month-1)*100; If counter>12 then YoY = (fnl_price/lag_year-1)*100;
... View more