I have daily stock returns and market return for 100 firms and for a number of years (Panel). I want to run a regression for each firm and year (i.e. my observations are my daily data) and save the residuals from each regression. So I wrote this:
Code:
egen group = group(Firm Year) su group, meanonly gen resi=. forval g = 1/`r(max)' { regress StockReturn MarketReturn if group == `g' predict r ,resid replace resi = r if group == `g' drop r }
Any Idea?
0 Response to regression loop !
Post a Comment