by sort pid (ob):gen cave = sum(calc)/ob
[...]
1) Where/When did -sum()- become an acceptable argument to
-generate-!?!? I have only ever seen it in the context of -egen-.
Looking at the help for -generate-, there are no arguments that are
explicitly stated to be useable. It is only at the very bottom of the
examples that one sees an function -uniform- and then -sum- used with
gen. Are the others? I know that using many egen arguments with -gen-
will return errors (e.g. count).
(I suppose you meant "bysort pid...".)