Hello! I have found posts about bits and pieces of this issue, but my efforts to piece the solutions together have not been fruitful so I am hoping for some help. I am looking to store certain coefficients and the residuals of a set of regressions that I am running on a panel dataset by group. I would like to store them as new variables in the dataset. I most recently tried:
There are 48 industries, which are mutually exclusive so each firm-year gets included in exactly one regression. The problem is that the variable coeff1 is equal to the same value for all observations, so the values from the 48th regression are being stored for all observations no matter what regression they are included in.
Is the best solution for this a for loop? Something like:
Code:
by industry: xtreg depvar indvar1 indvar2 indvar3 i.calendaryear, fe gen coeff1 = _b[indvar1]
Is the best solution for this a for loop? Something like:
Code:
forvalues i=1/48 {
quietly xtreg depvar indvar1 indvar2 indvar3 i.calendaryear if industry == 'i', fe
gen coeff'i' = _b[indvar1]
}

Comment