I want to calculate per id per row how many months there are before reaching the value 1 in a another colomn. I have a couple of thousands IDs en many months to work with.
id period sick
1 1-1-1990 0
1 1-2-1990 0
1 1-3-1990 1
1 1-4-1990 0
2 1-1-1990 0
2 1-2-1990 0
2 1-3-1990 1
2 1-4-1990 0
2 1-5-1990 0
and I would like to have an output like this
id period sick months_until
1 1-1-1990 0 2
1 1-2-1990 0 1
1 1-3-1990 1 0
1 1-4-1990 0 -1
2 1-1-1990 0 2
2 1-2-1990 0 1
2 1-3-1990 1 0
2 1-4-1990 0 -1
2 1-5-1990 0 -2