Thanks to Kit Baum, a new package called xtbalance2 is available on SSC.

xtbalance2 creates an indicator variable to identify a balanced subsample from an unbalanced dataset. The program tries to maximise the numbers of observations with respect to either the time dimension of the number of cross-sections/groups.

Example:
Code:
use http://www.stata-journal.com/software/sj12-1/st0246/manu_prod, clear
xtbalance2 , generate(balanceN) optimisation(N)
xtbalance2 lO lL lY, generate(balanceT) optimisation(T)
More examples and a detailed description are available in the help file.

How to install:
xtbalance2 can be installed via SSC
Code:
ssc install xtbalance2
or via my Github page which will frequently updated:
Code:
net from https://github.com/JanDitzen/xtbalance2
xtbalance2 is a new package and errors might occur. I would be grateful for any reports about bugs or problems here, by mail to me or via my Github page (https://github.com/JanDitzen/xtbalance2).

Thanks!