Stata 15 help for mf_panelsum
[M-5] panelsum() -- Panel sums
real matrix = panelsum(X, [weights,] info)
X: real matrix, possibly a view
weights: real colvector
info: real matrix, from panelsetup()
panelsum() computes within-panel sums of the columns of X according to
the panel information in info.
panelsum(X, weights, info):
X: r x c
weights: r x 1 (optional)
info: K x 2, K = number of panels
result: K x c
Function is built in.