Hi,

I am trying to estimate the discretionary accruals through the modified Jones model in Stata. This is the code I am running for, to estimate the discretionary accruals. I am using data from 75 companies from 2007 to 2019. I am sorry in advance for the errors in writing my post.


Here is the data format i am using.


Code:
FirmID    companies    years    Total_assets    laggedassets    SIZE
1    PEPCO HOLDINGS, INC    2007    15111000        16.530934
1        2008    16475000    15111000    16.617355
1        2009    15779000    16475000    16.574191
1        2010    14341000    15779000    16.478633
1        2011    14765000    14341000    16.50777
1        2012    15776000    14765000    16.574
1        2013    14848000    15776000    16.513376
1        2014    15667000    14848000    16.567067
1        2015    16311000    15667000    16.60735
1        2016    21019000    16311000    16.860937
1        2017    21243000    21019000    16.871538
1        2018    21972000    21243000    16.905279
1        2019    22706000    21972000    16.93814
2    NISOURCE INC    2007    18004800    22706000    16.706149
2        2008    20032200    18004800    16.812852
2        2009    19271700    20032200    16.774148
2        2010    19938800    19271700    16.808178
2        2011    20708300    19938800    16.846045
2        2012    21844700    20708300    16.899469
2        2013    22653900    21844700    16.935843
2        2014    24866300    22653900    17.029024



Here is the code I used, that I got from this same platform. I have also read all the FAQ but I am unable to find any workable code for me.

Code:
gen Jones_3 = .
forval y = 2007(1) 2019 {
forval i = 1(1) 75 {
display `i'
display `y'
reg TACC2 DAPterm1 DAPterm2 DAPterm3 if `i' == FirmID & `y' == years
predict r2 if `i' == FirmID & `y' == years
replace Jones_3 = r1 if `i' == FirmID & `y' == years
drop r2

}
}


This is the output that I get.

Code:
. forval y = 2007(1) 2019 {
  2.     forval i = 1(1) 75 {
  3.         display `i'
  4.         display `y'
  5.         reg TACC2 DAPterm1 DAPterm2 DAPterm3 if `i' == FirmID & `y' == years
  6.             predict r2 if `i' == FirmID & `y' == years
  7.             replace Jones_3 = r2 if `i' == FirmID & `y' == years
  8.             drop r2
  9.        
.     }
 10. }
1
2007
no observations
r(2000);

end of do-file

r(2000);

.
Just to let you know that I am using Thompson Reuters Data. I might be committing basic errors while writing the code but if I execute code without the 'if' conditions I get the required result. So, I am thinking that I m committing some error while writing' if' conditions or in classifying the FirmID and years as below. I do not know how we use industry and companies because I have run this code with FirmID, companies as, I do not have any Industry code.But these are all my guesses ,I still need your guidance and help in this regard.

This is the code i used by replacing FirmID,Industry and companies.I got same eroor after these.

Code:
forval y = 2007(1) 2019 {
forval i = 1(1) 75 {
display `i'
display `y'
reg TACC2 DAPterm1 DAPterm2 DAPterm3 if `i' == FirmID & `y' == years
predict r2 if `i' == FirmID & `y' == years


This is the result that i get when i run the code without 'if ' conditions.So can i run it without if conditions?
Code:

      Source |       SS           df       MS      Number of obs   =       881
-------------+----------------------------------   F(3, 877)       =   3469.79
       Model |  356.595872         3  118.865291   Prob > F        =    0.0000
    Residual |  30.0435815       877   .03425722   R-squared       =    0.9223
-------------+----------------------------------   Adj R-squared   =    0.9220
       Total |  386.639453       880  .439363015   Root MSE        =    .18509

------------------------------------------------------------------------------
       TACC2 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
    DAPterm1 |  -170208.8   45996.52    -3.70   0.000    -260484.9    -79932.7
    DAPterm2 |   -.199707   .0107229   -18.62   0.000    -.2207525   -.1786616
    DAPterm3 |   .5226463   .0120609    43.33   0.000     .4989748    .5463178
       _cons |  -.0007244   .0112775    -0.06   0.949    -.0228583    .0214096
------------------------------------------------------------------------------
I am sorry for the long post ,But i am trying to clearly state the problem that i am facing.This is my thesis data.


I am using stata 14.