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
Related Posts with Generating Variable Based On Several Conditions
Negative scale value using fixed effects quantile regression xtqregI have individual-level panel wealth-at-age data with 4600 observations on 350 individuals. Because …
2SLS For BeginnersI am would love some help understanding how to run a 2SLS. I am replicating a table and first ran an…
Manipulating local listsIn my code below I expected to get a local macro (myvars2) with a list of all my variables (which ar…
Can the attenuation bias of a demeaned dependent variable be solved by an control function approach?I recently demeaned my dependent variable by a group interaction. Mainly because simply adding them …
Export matrix to Word with asdocx after the predict commandProf River Huang asked the following question Dear Attaullah, Is it possible to put the results …
Subscribe to:
Post Comments (Atom)
0 Response to Generating Variable Based On Several Conditions
Post a Comment