Hi all,

I have an unbalanced panel. The complete panel spans 11 periods from 2004 to 2015. I would like to keep just the "balanced" firms having observations from 2004 to 2015. The unbalanced panel looks like:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double idfirm float Year
808 2004
808 2004
808 2004
808 2004
808 2005
808 2005
808 2005
808 2005
808 2006
808 2006
808 2006
808 2006
808 2007
808 2007
808 2007
808 2007
808 2008
808 2008
808 2008
808 2008
808 2009
808 2009
808 2009
808 2009
808 2010
808 2010
808 2010
808 2010
808 2011
808 2011
808 2011
808 2011
808 2012
808 2012
808 2012
808 2012
808 2013
808 2013
808 2013
808 2013
808 2014
808 2014
808 2014
808 2014
808 2015
808 2015
808 2015
808 2015
808 2004
808 2004
808 2004
808 2004
808 2005
808 2005
808 2005
808 2005
808 2006
808 2006
808 2006
808 2006
808 2007
808 2007
808 2007
808 2007
808 2008
808 2008
808 2008
808 2008
808 2009
808 2009
808 2009
808 2009
808 2010
808 2010
808 2010
808 2010
808 2011
808 2011
808 2011
808 2011
808 2012
808 2012
808 2012
808 2012
808 2013
808 2013
808 2013
808 2013
808 2014
808 2014
808 2014
808 2014
808 2015
808 2015
808 2015
808 2015
808 2004
808 2004
808 2004
808 2004
end
I have employed the following code:[CODE
]tempvar q
bysort idfirm Year: gen `q' = _n
gen byte balanced = 0
replace balanced = 1 if `q'==11

drop if balanced==0[/CODE]
do you think it is fine?