Dear Statalist,

I have a panel data on the level of towns and their administrative parts. Each town and administrative part has a unique id - id_town and id_part. For each town, I have an observation with data on the town as a whole (type=="O", id_part==0). If a town has more administrative parts than the one, there are also further observations consisting of data on the separate administrative parts (type=="K"). Every year, a certain value of coefficient is assigned by law to all towns based on their size. The coefficient is the same for all administrative parts of a town. However, a town can choose to change the value of the coefficient in some of its administrative parts.

I want to count how many towns decided to change the coefficient in some of its parts by year (i.e. when the coefficient in some of a town's administrative parts is different from the coefficient on a town level in a given year). Secondly, I want to know how many administrative parts inside the towns decided for such a change every year..

Thank you very much for a help.

The structure of the data is following:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int year long id_town str1 type long id_part double coefficient
2014 502316 "O"      0 3.5
2015 502316 "O"      0 3.5
2016 502316 "O"      0 3.5
2017 502316 "O"      0 3.5
2018 502316 "O"      0 3.5
2014 502545 "O"      0 1.4
2015 502545 "O"      0 1.4
2016 502545 "O"      0 1.4
2017 502545 "O"      0 1.4
2018 502545 "O"      0 1.4
2014 503444 "K" 621056 1.6
2015 503444 "K" 621056 1.6
2016 503444 "K" 621056 1.6
2017 503444 "K" 621056 1.6
2018 503444 "K" 621056 1.6
2014 503444 "K" 637157 1.6
2015 503444 "K" 637157 1.6
2016 503444 "K" 637157 1.6
2017 503444 "K" 637157 1.6
2018 503444 "K" 637157 1.6
2014 503444 "K" 637165 1.6
2015 503444 "K" 637165 1.6
2016 503444 "K" 637165 1.6
2017 503444 "K" 637165 1.6
2018 503444 "K" 637165 1.6
2014 503444 "K" 637181 1.6
2015 503444 "K" 637181 1.6
2016 503444 "K" 637181 1.6
2017 503444 "K" 637181 1.6
2018 503444 "K" 637181 1.6
2014 503444 "K" 637190 1.6
2015 503444 "K" 637190 1.6
2016 503444 "K" 637190 1.6
2017 503444 "K" 637190 1.6
2018 503444 "K" 637190 1.6
2014 503444 "K" 652784 1.6
2015 503444 "K" 652784 1.6
2016 503444 "K" 652784 1.6
2017 503444 "K" 652784 1.6
2018 503444 "K" 652784 1.6
2014 503444 "K" 746142 1.6
2015 503444 "K" 746142 1.6
2016 503444 "K" 746142 1.6
2017 503444 "K" 746142 1.6
2018 503444 "K" 746142 1.6
2014 503444 "K" 774332 1.6
2015 503444 "K" 774332 1.6
2016 503444 "K" 774332 1.6
2017 503444 "K" 774332 1.6
2018 503444 "K" 774332 1.6
2014 503444 "K" 774341 1.6
2015 503444 "K" 774341 1.6
2016 503444 "K" 774341 1.6
2017 503444 "K" 774341 1.6
2018 503444 "K" 774341 1.6
2014 503444 "O"      0   2
2015 503444 "O"      0   2
2016 503444 "O"      0   2
2017 503444 "O"      0   2
2018 503444 "O"      0   2
2014 503657 "O"      0 1.4
2015 503657 "O"      0 1.4
2016 503657 "O"      0 1.4
2017 503657 "O"      0 1.4
2018 503657 "O"      0 1.4
2014 503738 "O"      0 1.4
2015 503738 "O"      0 1.4
2016 503738 "O"      0 1.4
2017 503738 "O"      0 1.4
2018 503738 "O"      0 1.4
2014 503941 "K" 990043 1.4
2015 503941 "K" 990043 1.4
2016 503941 "K" 990043 1.4
2017 503941 "K" 990043 1.4
2018 503941 "K" 990043 1.4
2014 503941 "K" 990051 1.4
2015 503941 "K" 990051 1.4
2016 503941 "K" 990051 1.4
2017 503941 "K" 990051 1.4
2018 503941 "K" 990051 1.4
2014 503941 "K" 990094 1.4
2015 503941 "K" 990094 1.4
2016 503941 "K" 990094 1.4
2017 503941 "K" 990094 1.4
2018 503941 "K" 990094 1.4
2014 503941 "K" 990205 1.4
2015 503941 "K" 990205 1.4
2016 503941 "K" 990205 1.4
2017 503941 "K" 990205 1.4
2018 503941 "K" 990205 1.4
2014 503941 "K" 990213 1.4
2015 503941 "K" 990213 1.4
2016 503941 "K" 990213 1.4
2017 503941 "K" 990213 1.4
2018 503941 "K" 990213 1.4
2014 503941 "O"      0 1.4
2015 503941 "O"      0 1.4
2016 503941 "O"      0 1.4
2017 503941 "O"      0 1.4
2018 503941 "O"      0 1.4
end