Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Regression by industry and year excluding firm i

From   "Abdalla, Ahmed" <>
To   "" <>
Subject   st: Regression by industry and year excluding firm i
Date   Fri, 13 Dec 2013 17:33:22 +0000

Dear Statalist
I run a regression to estimate core earnings for each variable in my dataset. The regression is run using all observations in a particular industry year EXCLUDING firm i. Expected core earnings for firm i is estimated using the coefficients multiplied by the actual values of variables in the model for firm i.
I run the following code. 

First: I get an error message for macro length being exceeded.
Second: I try to use other commands for looping, the loop runs but it gives me error message for invalid syntax. 
My problem is on how to exclude firm i ? I hope if you have any suggestions regarding running regressions by industry and year and excluding firm i from the estimation procedures.

gen obs= [_n]
gen runn=1

gen b0=.
gen b1= .
gen b2=.
gen b3=.
gen b4=.
gen b5=.
gen b6=.

levelsof obs,local(levels)
foreach x of local levels{
gen mark=1 if obs==runn
gen sic_lp= sic_2 if obs ==runn
qui summ sic_lp
replace sic_lp = r(mean) if sic_lp==.
gen datadate_lp= datadate if obs == runn
qui summ datadate_lp
replace datadate_lp = r(mean) if datadate_lp==.
format datadate_lp %d
gen sample =1 if sic_lp== sic_2 & datadate_lp== datadate & sale !=. & wce !=. & wlag_ce=!=. & wato !=. & wacc !=. & wlag_acc!=. & wdsale !=. & wndsale !=. 
egen sample_sum= sum(sample) if mark != 1
capture reg wce wlag_ce wato wlag_acc wacc wdsale wndsale if sample==1 & mark != 1 & sample_sum >10
capture replace b0= _b[_cons]
capture replace b1= _b[wlag_ce] if obs==runn
capture replace b2= _b[wato] if obs==runn
capture replace b3= _b[wlag_acc] if obs==runn
capture replace b4= _b[wacc] if obs==runn
capture replace b5= _b[wdsale] if obs==runn
capture replace b6= _b[wndsale] if obs==runn
drop mark sic_lp datadate_lp sample sample_sum
replace runn= runn+1

gen pred_ce= b0+ b1*wlag_ce + b2*wato +b3*wlag_acc + b4*wacc + b5*wdsale + b6*wndsale

I appreciate your help

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index