I have an unbalanced panel data from year 2006 to year 2018.
There are firms with data as little as 1 year and also firms with all 13 years data.
I want a balanced data, and keep about 5 years data for each firm.
Means dropping firms which have less than 5 years data and also keeping the data for only 5 years for the firms having more than 5 years of data.
If I apply the following code, I only get to make subsample of firms with year 5... I want to create a subsample for regressions of firms with 5 years data. Its best if I can have data from last 5 years. For Example from 2013-2017(5 years) or 2013-2018(6 years) or something like this.
Code:
tempvar q bysort Firms: gen `q' = _n gen byte balanced = 0 replace balanced = 1 if `q'==5
Thank you so much!
Qazi
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str90 Name int Data_Year "3Com Corp" 2006 "3Com Corp" 2007 "3Com Corp" 2008 "3Com Corp" 2009 "3D Systems Corporation" 2006 "3D Systems Corporation" 2007 "3D Systems Corporation" 2008 "3D Systems Corporation" 2009 "3D Systems Corporation" 2010 "3D Systems Corporation" 2011 "3D Systems Corporation" 2012 "3D Systems Corporation" 2013 "3D Systems Corporation" 2014 "3D Systems Corporation" 2015 "3D Systems Corporation" 2016 "3D Systems Corporation" 2017 "3D Systems Corporation" 2018 "3M Company" 2006 "3M Company" 2007 "3M Company" 2008 "3M Company" 2009 "3M Company" 2010 "3M Company" 2011 "3M Company" 2012 "3M Company" 2013 "3M Company" 2014 "3M Company" 2015 "3M Company" 2016 "3M Company" 2017 "3M Company" 2018 "3Par Inc." 2008 "3Par Inc." 2009 "4Kids Entertainment Inc." 2006 "51job Inc Sponsored ADR" 2006 "51job Inc Sponsored ADR" 2007 "51job Inc Sponsored ADR" 2008 "51job Inc Sponsored ADR" 2010 "51job Inc Sponsored ADR" 2011 "51job Inc Sponsored ADR" 2013 "51job Inc Sponsored ADR" 2014 "51job Inc Sponsored ADR" 2016 "51job Inc Sponsored ADR" 2017 "51job Inc Sponsored ADR" 2018 "8x8, Inc." 2010 "8x8, Inc." 2011 "8x8, Inc." 2012 "8x8, Inc." 2013 "8x8, Inc." 2014 "8x8, Inc." 2015 "8x8, Inc." 2016 "8x8, Inc." 2017 "8x8, Inc." 2018 "99 Cents Only Stores LLC" 2006 "99 Cents Only Stores LLC" 2007 "99 Cents Only Stores LLC" 2008 "99 Cents Only Stores LLC" 2009 "99 Cents Only Stores LLC" 2010 "99 Cents Only Stores LLC" 2011 "A. M. Castle & Co." 2007 "A. M. Castle & Co." 2008 "A. M. Castle & Co." 2009 "A. M. Castle & Co." 2010 "A. M. Castle & Co." 2011 "A. M. Castle & Co." 2012 "A. M. Castle & Co." 2013 "A. M. Castle & Co." 2014 "A. O. Smith Corporation" 2006 "A. O. Smith Corporation" 2007 "A. O. Smith Corporation" 2008 "A. O. Smith Corporation" 2009 "A. O. Smith Corporation" 2010 "A. O. Smith Corporation" 2011 "A. O. Smith Corporation" 2012 "A. O. Smith Corporation" 2013 "A. O. Smith Corporation" 2014 "A. O. Smith Corporation" 2015 "A. O. Smith Corporation" 2016 "A. O. Smith Corporation" 2017 "A. O. Smith Corporation" 2018 "A.C. Moore Arts & Crafts Inc." 2006 "A.C. Moore Arts & Crafts Inc." 2007 "A.C. Moore Arts & Crafts Inc." 2008 "A.C. Moore Arts & Crafts Inc." 2009 "A.C. Moore Arts & Crafts Inc." 2010 "AAON, Inc." 2015 "AAON, Inc." 2016 "AAON, Inc." 2017 "AAON, Inc." 2018 "AAR CORP." 2006 "AAR CORP." 2007 "AAR CORP." 2008 "AAR CORP." 2009 "AAR CORP." 2010 "AAR CORP." 2011 "AAR CORP." 2012 "AAR CORP." 2013 "AAR CORP." 2014 "AAR CORP." 2016 "AAR CORP." 2017 "AAR CORP." 2018 end
0 Response to Unbalanced Panel data to balanced panel data for 5 Years
Post a Comment