Dear All,
I have a panel dataset for individual persons that looks like the following:
I would like to determine how many times each unique ID is repeated (i.e., how many years of data I have for each ID). The output I am looking for should include an additional column that shows the count of years for each ID, like so:
The example above shows one way I could calculate how many years of consistent data I have for each unique ID. However, if you have any other method or more efficient approach to achieve this, please let me know.
Thanks in advance for your help!
I have a panel dataset for individual persons that looks like the following:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(ID Year Income) 1 2001 10000 1 2003 20000 1 2005 15000 2 2001 1500 2 2003 100 2 2005 200 2 2007 300 2 2009 400 3 2001 5000 3 2003 600 4 2001 700 4 2003 120 4 2005 1500 4 2007 100 4 2009 200 4 2011 300 5 2001 400 5 2003 20000 5 2005 15000 end
I would like to determine how many times each unique ID is repeated (i.e., how many years of data I have for each ID). The output I am looking for should include an additional column that shows the count of years for each ID, like so:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(ID Year Income Repeat) 1 2001 10000 3 1 2003 20000 3 1 2005 15000 3 2 2001 1500 5 2 2003 100 5 2 2005 200 5 2 2007 300 5 2 2009 400 5 3 2001 5000 2 3 2003 600 2 4 2001 700 6 4 2003 120 6 4 2005 1500 6 4 2007 100 6 4 2009 200 6 4 2011 300 6 5 2001 400 3 5 2003 20000 3 5 2005 15000 3 end
The example above shows one way I could calculate how many years of consistent data I have for each unique ID. However, if you have any other method or more efficient approach to achieve this, please let me know.
Thanks in advance for your help!
Comment