Dear Statalist users -- Assume that we have the following toy example:

Code:
input firm_id year event event_5y
1    1979    0    1
1    1980    1    0
1    1981    0    0
1    1982    0    0
1    1983    0    0
1    1986    0    0
1    1987    0    0
1    1988    0    0
1    1989    0    0
1    1990    0    0
1    1991    0    0
1    1992    0    0
1    1993    0    0
1    1994    0    0
1    1995    0    0
1    1996    0    0
1    1997    0    0
1    1998    0    0
1    1999    0    0
1    2000    0    0
1    2001    0    0
1    2002    0    0
1    2003    0    1
1    2004    0    1
1    2005    0    1
1    2006    0    1
1    2007    0    1
1    2008    1    1
1    2009    0    1
1    2010    1    1
1    2011    0    0
1    2012    0    0
1    2013    0    0
1    2014    0    0
1    2015    0    0
1    2016    0    0
end
Assume that this dataset consists of three main variables: firm_id, year, and event. I am wondering how one can create an indicator variable that takes value one under the following condition. For each point in the future, the indicator should take value one if there is an event within a five-year period from time t. The fourth variable in this example is what I expect to get based on what I described above.

Is there any way to do this succinctly in Stata?