Dear all,

I want get the predicted value of each regression of each group? Here is an example.

Code:
webuse grunfeld,clear

forval i = 1/10{
    reg invest kstock if company == `i'
    predict y`i' if company == `i'
    predict e`i' if company == `i',res

}
egen y = rowtotal(y1-y10)
egen e = rowtotal(e1-e10)
y and e is what I wanted. But this is just a simple example. In my real data, I have 12000 companies.

Anyone have another simple method to get the predicted y and e of each group?