There is some discussion of related
problems in the Speaking Stata columns
in Stata Journal 3(3) and 3(4) 2003,
and pointers to pertinent software, but
that did not extend to any canned solution
yielding precisely this.
An alternative route starts from Roger Newson's
-pcontract- and -xcontract- (Roger:
why are there are two commands?).
The -pcontract- package was a first attempt. The -xcontract- package is a
slightly later package which supersedes the -pcontract- package, and which
should always be used. (Perhaps I should withdraw -pcontract- to prevent
confusion, but a lot of the Stata community do not seem to like people
withdrawing packages.)