I'm trying to retrieve a set of fixed effects in the most efficient way.

Suppose I have panel data with "id" as the identifier. Regressing:

Code:
reg i.pid
mat def B = e(b)
will make a matrix that will be the set of X id-specific coefficients.

I'd like to make the row names of matrix "B" the corresponding "id" value. That way, I can create a new .dta with "id" and "fixed_effects" variables and simply merge that to the database.

This would be easier if every id was included in the regression; however, some are dropped out (e.g. the base has 500 unique values for id and e(b) is a 432x1 vector).

Since Stata report legends from coefficients, I'm wondering if it's possible to connect those with the row names in a simple way.