naddiasimoes
> I'm regressing productivity on time for a panel of 2000 firms for
> five years. can someone tell me how can I create a macro and run a
> program with foreach, regressing this for each firm and store the
> coefficients in a matrix?
With the obvious reservations about fitting
a regression to subsets of five data points,
I recommend -statsby- for this problem.
That is, there is a wired-in command that
makes it unnecessary to write your own here.
If you really want a matrix, not variables,
to store results then use -mkmat-.
Another possibility would be to use the -parmest- package, downloadable
from SSC. (Type -ssc desc parmest- to find out more.) -parmby- is similar
to -statsby-, but it creates an output data set with 1 observation per
parameter per by-group, instead of 1 observation per by-group, and data on
estimates, confidence limits, P-values and other parameter attributes as
specified by the user.