#Count change of one variable within other variable

#1
Hi everyone,

hope a smart someone can help me with the following:

Data:

gvkey coname datadate fyear fyr
143668 MAGMA DESIGN AUTOMATION INC 20060331 2005 3
143668 MAGMA DESIGN AUTOMATION INC 20070331 2006 3
143668 MAGMA DESIGN AUTOMATION INC 20080331 2007 3
143668 MAGMA DESIGN AUTOMATION INC 20090430 2008 4
143668 MAGMA DESIGN AUTOMATION INC 20100430 2009 4
143668 MAGMA DESIGN AUTOMATION INC 20110430 2010 4
144356 SINO CLEAN ENERGY INC 20030930 2003 9
144356 SINO CLEAN ENERGY INC 20040930 2004 12
144356 SINO CLEAN ENERGY INC 20050930 2005 9
144356 SINO CLEAN ENERGY INC 20061231 2006 12
144356 SINO CLEAN ENERGY INC 20071231 2007 9
144356 SINO CLEAN ENERGY INC 20081231 2008 12

Question:
How do I count:
-# of "gvkey" that have a change in their fyr between datadate 20050101 and 20100101. In this case it would return 2
- # of changes in fyr within "gvkey" . Would return something like:

# Changes Freq.
0 0
1 1
2 0
3 0
4 0
5 1

Thanks so much!!

/Tessa