title: calculate difference in days lagged one year forward
body: <p>I have a table with id's and stop and start dates. I need to mutate a new column called "running_time_in_days" that finds the difference from one year's start date to the next years stop state for each id (the process carries over Jan 1, so the duration is over the new year). </p>
  
  <pre><code>library(readr)
  library(dplyr)
  library(lubridate)
  
  # read in some test data
  test &lt;- read_csv("id, measure, measure_date
          1, start, 1998-10-3 
          1, stop, 1999-5-1
          1, stop, 2000-4-15
          1, start, 1999-11-9
          2, stop, 2000-6-1
          2, stop, 1999-5-25
          2, start, 1999-12-1 
          2, start, 1998-11-12")
  # format "measure_date" as a date
  test$measure_date &lt;- test$measure_date %&gt;% as_date('%Y-%m-%d')
  </code></pre>
  
  <p>The output could look something like this in wide form:</p>
  
  <pre><code>    id      start       stop        duration
      1   1998-10-03  1999-05-01  stop - start (days)
      1   1999-05-01  2000-04-15  stop - start (days)
      2   1998-11-12  1999-05-25  stop - start (days)
      2   1999-12-01  2000-06-01  stop - start (days)
  </code></pre>