Hi Statalisters,

I am working on the Bacon decomposition (using bacondecomp command), which requires a strongly balanced panel.
The panel dataset I am working on was unbalanced, so I performed the following code to convert it into a balanced panel :

Code:
bysort district:  gen nyear=[_N]
tab nyear
keep if nyear==18
After this conversion, I get a "WEAKLY" balanced dataset (according to the xtset id time results), hence the bacondecomp is not working. What transformation can I make to convert the dataset into a "STRONGLY" balanced panel?

I came across this definition of a "strongly balanced" panel: "When the dataset contains a time variable, panels are said to be strongly balanced if each panel contains the same time points, weakly balanced if each panel contains the same number of observations but not the same time points, and unbalanced otherwise." (https://www.stata.com/statalist/arch.../msg00101.html).

However, after the conversion I made, my panel dataset contains 585 districts and each district counts 18 years of data. Why is it still "weakly" balanced? How can I fix this issue?


Please find below a sample the data I am using:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double district float(year lny x)
10101 2000 15.752553 0
10101 2001 16.193884 0
10101 2002 16.471481 0
10101 2003 16.605242 0
10101 2004  17.15857 0
10101 2005  17.22689 0
10101 2006 17.527142 0
10101 2007 18.355291 0
10101 2008 18.943258 0
10101 2009  18.69728 0
10101 2010 18.725645 0
10101 2011 18.640745 0
10101 2012 19.338213 0
10101 2013  19.44976 0
10101 2014 18.819197 0
10101 2015 19.055973 0
10101 2016 19.063976 0
10101 2017  19.14196 0
10103 2000  13.91526 0
10103 2001 13.926852 0
10103 2002 14.537033 0
10103 2003 14.863282 0
10103 2004  15.23191 0
10103 2005  15.82604 0
10103 2006 15.940092 0
10103 2007 16.163109 0
10103 2008 16.602633 0
10103 2009 16.625645 0
10103 2010  16.94231 0
10103 2011 17.234108 0
10103 2012  17.08096 0
10103 2013 17.589808 0
10103 2014 17.507406 0
10103 2015 17.655422 0
10103 2016 17.713999 0
10103 2017  17.98462 0
10105 2000 17.176313 0
10105 2001 17.218447 0
10105 2002  17.22451 0
10105 2003 17.351425 0
10105 2004 18.095589 0
10105 2005 18.538553 0
10105 2006 18.711836 0
10105 2007  19.08575 0
10105 2008  19.27568 0
10105 2009  19.96377 0
10105 2010  19.67612 0
10105 2011 19.225895 0
10105 2012 19.719824 0
10105 2013 19.645073 0
10105 2014 19.229593 0
10105 2015 19.285046 0
10105 2016 19.239407 0
10105 2017   19.5521 0
10107 2000 16.896315 0
10107 2001  17.19038 0
10107 2002  17.37088 0
10107 2003  17.51199 0
10107 2004 18.074612 0
10107 2005 18.092892 0
10107 2006 18.189089 0
10107 2007 18.554443 0
10107 2008  19.16435 0
10107 2009 18.798866 0
10107 2010  19.15159 0
10107 2011  19.48421 0
10107 2012    19.636 0
10107 2013 19.558506 0
10107 2014  19.60922 0
10107 2015 19.698847 0
10107 2016  19.85667 0
10107 2017  20.01661 0
10109 2000 17.288967 0
10109 2001  17.53965 0
10109 2002 17.691305 0
10109 2003 17.912817 0
10109 2004 18.181335 0
10109 2005 18.984133 0
10109 2006 19.162714 0
10109 2007 18.920141 0
10109 2008 18.706972 0
10109 2009  19.65674 0
10109 2010 19.695604 0
10109 2011  20.01785 0
10109 2012  20.11707 0
10109 2013  19.93405 0
10109 2014  19.91495 0
10109 2015 19.680166 0
10109 2016 19.603456 0
10109 2017 19.917625 0
end
Thank you
Marina