Assume your group variable name is var_group,the value of which ranges from 1 to 480, your dependent variable is y, and independent variables are x1, x2 and x3. Then You may try codes here below:
gen residual = .
forval i = 1/480{
reg y x1 x2 x3 if var_group == `i'
capture drop res_temp
predict res_temp if var_group == `i'
replace residual = res_temp if var_group == `i'
drop res_temp
}