Hello -
I am venturing into my first archival study and am struggling with figuring out the Stata code to estimate total accruals and discretionary accruals. Could someone please help me?
I have tried the following code from a blogger but it is not working for me.
gen sic_2= substr(sic,1,2)
destring sic_2, replace
vallist sic_2
local a =r(list)
vallist fyear
local b =r(list)
gen uhat=.
xtset gvkey fyear
gen obs= [_n]
summ obs
scalar e= r(min)
scalar f= r(max)
gen ta= (ib-oancf)/L.at
gen x1= 1/L.at
gen x2= (d.revt – d.rect)/L.at
gen x3= ppegt/L.at
foreach i in `a’ {
foreach x in `b’ {
forvalues j= `=scalar(e)’/`=scalar(f)’ {
capture noisily reg ta x1 x2 x3 if sic_2==`i’ & fyear==`x’ & obs != `j’, nocons
capture noisily predict uhat_2, resid
capture noisily replace uhat_2=. if e(N) < 10
capture noisily replace uhat= uhat_2 if sic_2==`i' & fyear==`x' & obs== `j'
capture noisily drop uhat_2
di `i'
di `x'
di `j'
}
}
}
Thank you very much.
I am venturing into my first archival study and am struggling with figuring out the Stata code to estimate total accruals and discretionary accruals. Could someone please help me?
I have tried the following code from a blogger but it is not working for me.
gen sic_2= substr(sic,1,2)
destring sic_2, replace
vallist sic_2
local a =r(list)
vallist fyear
local b =r(list)
gen uhat=.
xtset gvkey fyear
gen obs= [_n]
summ obs
scalar e= r(min)
scalar f= r(max)
gen ta= (ib-oancf)/L.at
gen x1= 1/L.at
gen x2= (d.revt – d.rect)/L.at
gen x3= ppegt/L.at
foreach i in `a’ {
foreach x in `b’ {
forvalues j= `=scalar(e)’/`=scalar(f)’ {
capture noisily reg ta x1 x2 x3 if sic_2==`i’ & fyear==`x’ & obs != `j’, nocons
capture noisily predict uhat_2, resid
capture noisily replace uhat_2=. if e(N) < 10
capture noisily replace uhat= uhat_2 if sic_2==`i' & fyear==`x' & obs== `j'
capture noisily drop uhat_2
di `i'
di `x'
di `j'
}
}
}
Thank you very much.
Comment