Look at -statsby-. Alternatively, 
gen rsq = . 
egen group = group(firm) 
su group, meanonly 
qui forval i = 1/`r(max)' { 
	regress <whatever> if group == `i' 
	replace rsq = e(r2) if group == `i' 
} 
Nick 
[email protected] 
[email protected]
 
> I am trying to construct an earnings quality metric based on 
> the R2 from firm
> specific regressions of returns on accounting values. I know 
> how to run the
> firm specific regressions. I am wondering if it possible to 
> create a variable
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/