How to create conditional dummies “before the event” with dplyr in R?
问题 I'm trying create a condition dummy (X) with the rule set X=1 if Y=1 the last two years before the NA (only count once!). To give an example: this is a sample from my data: year country Y 1990 Bahamas 1 1991 Bahamas NA 1992 Bahamas NA 1993 Bahamas 0 1994 Bahamas 1 1995 Bahamas 1 1996 Bahamas NA 1997 Bahamas 1 1998 Bahamas NA 1999 Bahamas 1 2000 Bahamas NA 2001 Bahamas 1 2002 Bahamas 1 2003 Bahamas 0 2004 Bahamas NA 2005 Bahamas 0 2006 Bahamas 0 2007 Bahamas 1 2008 Bahamas NA 2009 Bahamas 1