Dear board members,

the simplified structure of my data is as follows: i have a panel data set on the municipal level with several variables over the course of nine years. Each municipality has a specific code and is also part of a geographic region with another specific code. Now, I would like to create a new dummy variable for each municipality and year that takes the value of one if the "original variable" is 1 in either n or n-1 in any municipality that is part of the same geographic region, but not in the municipality itself.
To illustrate even further, say a municipality Alpha is part of a county Beta that consists of 15 municipalities overall. I have observations whether a significant change has happened in each of these municipalities in every year (the "original variable" takes 1 in this case). Now, for any given year, the new variable should take the value one for Alpha if the significant change has occured within the last two years in any municipality in Beta, and, in case there were only one or two changes in the 30 observations of the last two years, that change must not have happened in Alpha. I hope this makes it relatively clear.

Any ideas how to achieve this? Your help is appreciated.

Kind regards,
Will