Hello I have a fairly tricky question which might either have a very simple solution I fail to see or demands some creativity.

For the example below I would like to calculate how many observations per nomem_encr (which is the Id of a participant) I have on average. To clearify, For example for Individual 800009 I have observations for 2015-2022 so 8 years. For other Id's I have far less. Is there a way I could check how many years of observation I have on average?

could I group them and then maybe calculate an average of group size?

Thank you in advance!


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double nomem_encr float year
800009 2015
800009 2016
800009 2017
800009 2018
800009 2019
800009 2020
800009 2021
800009 2022
800012 2015
800015 2015
800015 2016
800015 2017
800015 2018
800015 2019
800015 2020
800015 2021
800015 2022
800042 2015
800042 2016
800042 2018
800054 2015
800054 2016
800054 2017
800054 2018
800054 2019
800057 2015
800057 2016
800057 2017
800057 2018
800057 2019
800057 2020
800057 2021
800057 2022
800058 2020
800058 2021
800058 2022
800073 2017
800073 2018
800073 2019
800085 2015
800085 2016
800085 2017
800085 2018
800085 2019
800085 2020
800085 2021
800085 2022
800100 2015
800100 2016
800100 2017
800100 2018
800100 2019
800100 2020
800100 2021
800100 2022
800115 2017
800119 2015
800119 2016
800119 2018
800119 2019
800119 2020
800119 2021
800119 2022
800127 2020
800127 2021
800127 2022
800128 2017
800128 2018
800128 2020
800128 2021
800131 2015
800131 2016
800131 2017
800131 2018
800131 2019
800131 2020
800131 2021
800131 2022
800151 2017
800161 2015
800161 2016
800161 2017
800161 2018
800161 2019
800161 2020
800161 2021
800161 2022
800170 2015
800170 2016
800170 2017
800170 2018
800170 2019
800170 2020
800170 2021
800170 2022
800186 2015
800186 2016
800186 2017
800186 2018
800186 2019
end