Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Estimating discretionary accruals using modified jones model by company and year (r111 error)

    Hi there,

    I am trying to estimate the discretionary accruals of the modified Jones model in Stata. However, I keep getting the error r(111) which says: variable term not found. I think something might be wrong with my variable fyear. These are the properties of the variable fyear: Type-double and Format-%ty.

    This is the code I am running for to estimate the discretionary accruals:
    gen Jones_2005_TAC2=.
    forval y = 2014(1)2019{
    forval i = 1(1) 22426{
    display `i'
    display `y'
    reg TACC_2 term1 term 2 term3 if `i'==Industry_code & `y'==fyear, noconstant
    predict r if `i'==Industry_code & `y'==fyear, resid
    replace Jones_2005_TAC2=r if `i'==Industry_code & `y'==fyear
    drop r
    }
    }

    This is what Stata says when I run it:
    . gen Jones_2005_TAC2=.
    (22,458 missing values generated)

    . forval y = 2014(1)2019{
    2. forval i = 1(1) 22426{
    3. display `i'
    4. display `y'
    5. reg TACC_2 term1 term 2 term3 if `i'==Industry
    > _code & `y'==fyear, noconstant
    6. predict r if `i'==Industry_code & `y'==fyear,
    > resid
    7. replace Jones_2005_TAC2=r if `i'==Industry_cod
    > e & `y'==fyear
    8. drop r
    9. }
    10. }
    1
    2014

    variable term not found
    r(111);


    Hope someone can help me out. It is for my thesis!

    Kind regards,
    Sarah

  • #2
    Code:
    term 2
    should be

    Code:
    term2

    Comment


    • #3
      Thank you for your quick reply! I have changed the code and am now getting the error r(2000) no observation for 2014.
      I have typed the code:
      count if !missing(fyear)

      And it says that all of observations are missing values which is strange because they all have values in them. Do you maybe know what could be the problem here?

      Comment


      • #4
        Stata implements listwise deletion of missing values, which means that a missing value in any of your variables will lead to the entire observation being dropped. This suggests that you have missing values for one or more of the variables TACC_2, term1, term2 and term3 for one or more industries in 2014. You can suppress the error and allow the code to continue using capture.

        Code:
        gen Jones_2005_TAC2=.
        forval y = 2014(1)2019{
           forval i = 1(1) 22426{
              display `i'
              display `y'
              capture noisily{
                 reg TACC_2 term1 term 2 term3 if `i'==Industry_code & `y'==fyear, noconstant
                 predict r if `i'==Industry_code & `y'==fyear, resid
                 replace Jones_2005_TAC2=r if `i'==Industry_code & `y'==fyear
                 drop r
              }
           }
        }

        Comment


        • #5
          I have added this command and it is running now but keeps saying that for all the years there are no observations. Is there a way to change the value of fyear so Stata can see them as non-missing/

          Comment


          • #6
            I will need to see a sample of your data to know whether your regressions can run or you really do not have data. Copy and paste the output from the following:

            Code:
            sort Industry_code fyear
            dataex Industry_code fyear TACC_2 term1 term2 term3 in 1/50

            Comment


            • #7
              Code:
              * Example generated by -dataex-. To install: ssc install dataex
              clear
              input float Industry_code double fyear float(TACC_2 term1 term2 term3)
              1 2014            .            .             .          .
              1 2014            .            .             .          .
              1 2014            .            .             .          .
              1 2014            .            .             .          .
              1 2014            .            .             .          .
              1 2014            .            .             .          .
              1 2014            .            .             .          .
              1 2014            .            .             .          .
              1 2014            .            .             .          .
              1 2014            .            .             .          .
              1 2014            .            .             .          .
              1 2015    -5.681818     3.787879     .13257577          0
              1 2015   -.08892404   .004912388      .3165494   1.874896
              1 2015   -.06305835  .0003737898     .04821889   .4543042
              1 2015      .164138   .002659398     .17770095 .034066886
              1 2015   -.03244044  .0023141988 -.00024299086   .6986034
              1 2015   -.08433607  .0004032209     -.0295319 .015898598
              1 2015    -40.08333    20.833334     .27083334  .22916667
              1 2015  -.010419696     .0484637     -.6389454  .57545793
              1 2015            .            .             .          .
              1 2015    -.1598656   .011198208      .3323068  .12852183
              1 2015 -.0024753874  .0040381523    -.01272422    .908657
              1 2015            .            .             .          .
              1 2016  -.011638756  .0023152488   -.012895937   .7277406
              1 2016   -.05072735  .0021711756     -.0193734   .8234118
              1 2016  -.023174016   .003710217     .04258587    .943256
              1 2016   -.04106159 .00038519315   -.017333692   .4899657
              1 2016     -5.12963      6.17284     .10493828          0
              1 2016   -.05191143  .0081737405     .12125745  .10725583
              1 2016   -.05254475   .002004454    -.27468035   .1863581
              1 2016    .02707072   .003056076    -.29267427  .05070335
              1 2016    -.0489162    .05795757     .02098064   .6690043
              1 2017   -.03139245  .0018277992     .02656889   .1639207
              1 2017  -.025892597  .0022742727   -.022560786   .7545651
              1 2017   -.01198378   .007873706     -.1627495  .10694067
              1 2017     -.082152  .0021802548    -.03132372   .7616436
              1 2017     -.084927     .1028172    .003187333  1.1485709
              1 2017  -.027663663  .0003768892     .02804055  .50062186
              1 2017   -.04280792   .003749489    .033617917  .07733321
              1 2017   -14.530613    20.408163    -1.8163266          0
              1 2017   -.03891661  .0032738796    .031167336   .8816787
              1 2018   -.01432552  .0023855986    -.11581604   .8120649
              1 2018  -.019488653  .0019297607    .019224275   .6723749
              1 2018   .005282703  .0029495826     .02384148    .981748
              1 2018    .12491626   .003742473     .08257392    .115474
              1 2018            .            .             .          .
              1 2018   -20.757576     30.30303     -.6969697          0
              1 2018     .1492229    .00853971    -.09639625  .11255337
              1 2018   -.09704001  .0003614153     .14745745   .5031624
              1 2019  -.031518802  .0003072008   -.001505284   .4808614
              end
              format %ty fyear

              Comment


              • #8
                As you can see, you have no data for 2014 (at least for industry 1). If this is the case for all industries, just drop these observations and consider your sample period starting at 2015.

                Code:
                sum TACC_2 if fyear==2014
                local obs= r(N)
                if `obs'==0{
                   drop if fyear==2014
                }
                gen Jones_2005_TAC2=.
                sum fyear if Industry_code==1
                forval y = `r(min)'/2019{
                   forval i = 1/22426{
                      display `i'
                      display `y'
                      capture noisily{
                         reg TACC_2 term1 term 2 term3 if `i'==Industry_code & `y'==fyear, noconstant
                         predict r if `i'==Industry_code & `y'==fyear, resid
                         replace Jones_2005_TAC2=r if `i'==Industry_code & `y'==fyear
                         drop r
                      }
                   }
                }

                Comment


                • #9
                  I changed the code and it ran. But in the end I got these:
                  no observations
                  22413
                  2019
                  no observations
                  22414
                  2019
                  no observations
                  22415
                  2019
                  no observations
                  22416
                  2019
                  no observations
                  22417
                  2019
                  no observations
                  22418
                  2019
                  no observations
                  22419
                  2019
                  no observations
                  22420
                  2019
                  no observations
                  22421
                  2019
                  no observations
                  22422
                  2019
                  no observations
                  22423
                  2019
                  no observations
                  22424
                  2019
                  no observations
                  22425
                  2019
                  no observations
                  22426
                  2019
                  no observations


                  .
                  end of do-file

                  Does that mean that for some industries there are year observations?

                  Comment


                  • #10
                    I just checked the summary of the Industry_code variable and the max is 378 so it could be that the missing observations are due to this?

                    Comment


                    • #11
                      Yes, it means that for some industries, e.g., 22425, you have 1 or no observations in 2019. This should not matter as you have generated your wanted variable which will have missing values for those combinations of industry and year with less than 2 observations. You can suppress the display of these error messages by changing

                      Code:
                      capture noisily
                      to

                      Code:
                      capture quietly

                      EDIT:

                      I just checked the summary of the Industry_code variable and the max is 378 so it could be that the missing observations are due to this?
                      Yes, then a lot of those industries that you include in your code do not exist. So change

                      Code:
                      forval i = 1/22426{
                      to

                      Code:
                      forval i = 1/378{
                      Last edited by Andrew Musau; 05 May 2020, 05:45.

                      Comment


                      • #12
                        Thank you for your help!!

                        Comment

                        Working...
                        X