I am trying to concord districts using my panel dataset for 12 years. some districts are newly carved out of older districts. For, example, a new district Agar Malwa was formed from the district Shajapur in 2014. I want to add Agar Malwa to Shajapur everytime it appears after 2014 and get only new combined Shajapur in my data set dropping Agar Malwa and Shajapur from it.
My dataset looks like following-
Year | District | State | values |
---|---|---|---|
2012 | Shajapur | x | 23 |
2013 | Shajapur | x | 21 |
2014 | Shajapur | x | 16 |
2014 | Agar Malwa | x | 8 |
2015 | Shajapur | x | 17 |
2015 | Agar Malwa | x | 10 |
upto year 2021. I need the new dataset in the following manner-
Year | District | State | values |
---|---|---|---|
2012 | Shajapur | x | 23 |
2013 | Shajapur | x | 21 |
2014 | Shajapur | x | 24 |
2015 | Shajapur | x | 27 |
up to year 2021. I have to do this for about 100 districts and which were formed, renamed, bifurcated between 2010 and 2021. Please suggest some loop code, or some basic code which can be used here.