This is my code:
data = @pipe data |> sort(_, :year) |> groupby(_,:id) |> transform(_, :a1 => (x -> lead(x,1) .- x ) => :b1; ungroup = false)