Hello, Please help! We have a dataset and we need a code with a loop that will run statistics and regressions on all sic codes for ten years for one country.

This is Jones Model - Accruals measures.

Please ignore what is written in the Paretheses for Compustat data.

Array
Array


We ran the below codes but only for one country and two sic codes. We need to do our whole dataset so we need a loop that will do automatically. Please, can anyone help us with this? Thank you very much in advance.

destring gvkey, replace
destring sic, replace
gen sic2=int(sic/100)
drop if (fic !="AUS")
tsset gvkey FISCAL_YEAR
gen l1at=l.at
gen Accruals=( nicon-oancf)/l1at
gen l1revt=1.revt
gen changerev=(revt-l1revt)
gen l1rect=1.rect
gen changerect=(rect-l1rect)
gen chgrevchgrec = (changerev-changerect)/l1at
gen ppegtl1at=ppegt/l1at
gen invl1at=1/l1at
reg Accruals invl1at chgrevchgrec ppegtl1at
predict earningsmanagement, resid