title: dplyr: Filter within years prior to marked time period
body: <p>I want have a list of year-country specific dummies and I want to also mark years <em>two years</em> prior to those years that are marked.</p>
  
  <p>The data looks like this</p>
  
  <pre><code>library(tidyverse)
  
  df &lt;- tribble(
    ~year, ~country, ~occurrence, 
    #--|--|----
    2003, "USA", 1,
    2004, "USA", 0,
    2005, "USA", 0,
    2006, "USA", 0,
    2007, "USA", 0,
    2008, "USA", 0,
    2009, "USA", 0,
    2010, "USA", 0,
    2011, "USA", 1,
    2012, "USA", 0,
    2013, "USA", 0,
    2005, "FRA", 0,
    2006, "FRA", 0,
    2007, "FRA", 1,
    2008, "FRA", 1,
    2009, "FRA", 0,
    2010, "FRA", 0,
    2011, "FRA", 0,
    2012, "FRA", 0,
    2013, "FRA", 0,
    2014, "FRA", 0,
    2015, "FRA", 1
  )
  </code></pre>
  
  <p>So for <code>"USA"</code> I also want to put a <code>1</code> into column <code>occurence</code> for the years 2009 and 2010 and for <code>FRA</code> the years 2005, 2006, 2013 and 2014.</p>
  
  <p>I thought about doing something like this:</p>
  
  <pre><code>df %&gt;%
    group_by(country) %&gt;%
    mutate(occurence = ifelse("not sure what to put here"),
                              1,
                              0))
  </code></pre>
  
  <p>But I'm not sure how to tell R only to filter for the years I want.</p>