A loop of cross-sectional regressions for calculating abnormal accruals in Stata

I write a loop of cross-sectional regressions for calculating abnormal accruals. This program can be easily modified and replaced with Jones, modified Jones, or Dechow and Dichev model.

I add detailed comments in the program to help you prepare the input file.

This entry was posted in Stata. Bookmark the permalink.

7 Responses to A loop of cross-sectional regressions for calculating abnormal accruals in Stata

  1. Renee Adebile says:

    I am using your codes to calculate DA. However, I get ” Invalid Syntax”. Can you please help me figure out what I do wrong.
    this the codes I used;
    forvalues i=1/num' {
    regress ta x1 x2 x3 x4 x5 if groupid==
    i’
    predict resid if groupid==i', residuals
    replace da=resid if groupid==
    i’
    drop resid
    replace regobs=e(N) if groupid==i'
    replace df=e(df_r) if groupid==
    i’
    replace r2a=e(r2_a) if groupid==i'
    foreach x in x1 x2 x3 x4 x5 _cons {
    replace
    x’_b=_b[x'] if groupid==i’
    replace x'_se=_se[x’] if groupid==`i’
    }
    }

  2. Renee Adebile says:

    those are the entire codes I used:
    * Remove obs without required data
    foreach v in ta x1 x2 x3 x4 x5 {
    drop if v'==.
    }

    * Handle outliers for each industry year
    ge trunc=0
    local vlist "ta x1 x2 x3 x4 x5"
    egen groupid=group(fyear sic_2)
    sum groupid, meanonly
    local num=r(max)
    forvalues i=1/
    num’ {
    foreach v in vlist' {
    _pctile
    v’ if groupid==i', p(1 99)
    replace trunc=1 if groupid==
    i’ & (v'r(r2)) //drop top and bottom 1%. You can do winsorize as well
    }
    }
    drop if trunc==1
    drop trunc groupid

    * Require at least 20 obs for each estimation
    bysort groupid: egen obsnum=count(fyear)
    keep if obsnum>=20
    drop groupid
    egen groupid=group(fyear sic_2)
    sum groupid, meanonly
    local num=r(max)

    * Run cross-sectional regressions
    ge da=.
    ge regobs=.
    ge df=.
    ge r2a=.

    foreach x in x1 x2 x3 x4 x5 _cons {
    ge
    x’_b=.
    ge x'_se=.
    }

    forvalues i=1/num’ {
    regress ta x1 x2 x3 x4 x5 if groupid==i'
    predict resid if groupid==
    i’, residuals
    replace da=resid if groupid==i'
    drop resid
    replace regobs=e(N) if groupid==
    i’
    replace df=e(df_r) if groupid==i'
    replace r2a=e(r2_a) if groupid==
    i’
    foreach x in x1 x2 x3 x4 x5 _cons {
    replace x'_b=_b[x’] if groupid==i'
    replace
    x’_se=_se[x']if groupid==i’
    }
    }

    save da, replace

    Note that when I run all the entire codes, I get da regobs r2a x1_b for the first regression. and then I get ” invalid syntax”.

  3. Suleman says:

    I am working on discretionary accrual model. I am having problem with calculating the Total accrual and PPE in Stata . I used this command :gen TAC =(NI-CFO)/lagged TA and Gross property plant and equipment using the following command :gen var name =PPE/lagged TA. How do I go about it please

    • Kai Chen says:

      Do you mean you don’t know how to calculate lagged TA? If this is your problem, check the command tsset in Stata documentation. Stata is very powerful in calculating lagged value or changes in value.

  4. Razoo says:

    Hello Kai,

    Could you please provide us with the modified jones model’s code?

    Thanks a lot,

  5. Hui says:

    Hello Dr. Chen,

    I just want to say thank for sharing the helpful codes and instructions. I just replicated Jones and Mod Jones by following your codes, and it really helps me to write it in a more efficient way.

    Thank you once again.
    Hui

Leave a Reply to Renee Adebile Cancel reply

Your email address will not be published. Required fields are marked *