Dear all,
I would like to get the residual of cross-sectional regression for every industry-year combination. In particular, I would like to run a regression of cash flow on assets and sales for each industry-year combination. After getting the coefficients including constant, I want to plug them to get the predicted cash flow and use the difference between actual cash flow and predicted cash flow (residuals). Following is my data and I ran the following commands.

Code:
input str1 firm float (cashflow assets sales) int year str1 industry
"a" 100 500 300 1991 1
"a" 125 550 410 1992 1
"a" 129 550 350 1993 1
"a" 118 450 216 1994 1
"a" 96 600 175 1995 1
"b" 350 1500 600 1991 1
"b" 560 1675 850 1992 1
"b" 730 1300 755 1993 1
"b" 900 1800 1065 1994 1
"b" 1050 2000 1800 1995 1
"c"  60 120 155 1991 2
"c"  -10  120 180 1992 2
"c"  50 160 168 1993 2
"c"  200 150 260 1994 2
"c"  -60 140 200 1995 2
"d" 155  230 200 1991 2
"d" 255 398 400 1992 2
"d" 179 398 268 1993 2
"d" 196 423 318 1994 2
"d" 165 300 215 1995 2
end
Code:
encode firm,gen(id)
*for setting the panel      
xtset id year
*for saving the data
save "C:\Users\vishnu\Desktop\demo.dta"
*running the regression as year-industry combination
statsby, by( year industry ) : regress cashflow assets sales                
*since the above regression replaces the old data with coefficients , I need to merge the results of regression with old data
merge 1:m industry year using "C:\Users\vishnu\Desktop\demo.dta."
* plugging coefficients to get predicted values              
gen predicted_cashflow=_b_cons+(_b_assets*assets)+(_b_sales*sales)
*calculating the residual        
gen residual cashflow=cashflow-predicted_cashflow
Question 1 , What is the simple procedure to get the residuals with the industry-year combination in a set up like above? My codes are very inefficient.
Question 2, How to put additional restriction regarding the minimum no: of observations required to run the regression(say, for every industry-year combination with minimum 3 observations.

If my question is vague or ambiguous, please let me know.
Expecting the help of forum in this issue.