Announcement

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

  • "foreach" regression by industry and year

    Hello,

    i´m currently working on modified jones model to detect Earnings Management.


    Modified Jones Model:


    TA = Total accruals
    REV = Revenues
    REC = Receivables
    PPE = Property Plant and Equipment
    1/Ait-1 = Lagged assets

    NA = normal Accruals:



    At the end i want to get the discretionary part of total accruals:
    DA = Discretionary Accruals
    so that: TA - NA = DA!

    Now i have to do the regression by industry (variable: sic_2) and year (fyear).

    I know that i have to use kind of this code

    foreach ….. {


    reg TA x1 x2 x3 if fyear == 2000 & digit_2_sic == 10,nocon

    bysort id: replace normal_Accruals= _b[x1]*x1 + _b[x2]*x2 + _b[x3]*x3 if fyear == 2000 & digit_2_sic == 10


    }

    while: x1 = 1/Ait-1 x2= (deltarev-deltarec)/Ait-1 X3 = PPE/Ait-1


    My saple consisty of years from 2000-2014 and sic_2 from 1-99. How can i write the code, so that i don´t have to do the regression seperately for each year and industry?!
    Is there something like a loop? Furthermore i get the error: invalid Syntax or no observations if i try it for a single year and sic_2 like above. How do i have to write the code in stata exactly?

    I would be very very happy if someone could help me!!
    Thank you in advance

    Lana



  • #2
    Modified Jones Model: TA/Ait-1 = α1i(1/Ait-1)+ α2i(∆REV-∆REC)/Ait-1 + α3i (PPE)/Ait-1 + εit


    NDA= α1i(1/Ait-1)+ α2i((∆REV-∆REC)/Ait-1)+ α3i (PPE/Ait-1)

    Comment


    • #3
      You didn't get a quick answer. You'll increase your chances of a useful answer if you follow the FAQ on asking questions - provide Stata code in code delimiters, Stata output, and sample data using dataex. In debugging, you may find set trace on helpful - it will tell you how Stata is interpreting your code. I'd also make sure that the code works for one or two industry/year combinations where you set the industry/year specifically before putting it in the loop. This will help you get part right before adding the loop.

      You could set up a loop with all your industries listed and a loop with all your years listed. Then you can run your routine for each year/industry pair. Alternatively, you can use statsby to do your regressions by industry and year. I think this can give you a file with the parameters. Then you'd merge the parameter file with your main data and calculate the predicted values.

      In either case, you may hit a problem if you have an industry without usable observations. Capture will let Stata continue even when a routine returns an error code.

      By the way, after a regression you can do predictions using predict rather than writing out the equation. I suspect this does not work with statsby.

      Comment


      • #4
        Thank you for answering!!!

        In the past days i run threw the regression and finally came to my results.
        But then the next Problem occured. I got a relatively low R² (0.004), which tend to be higher if i didn´t regress discretionary accruals but the natural logarithm of discretionary accruals as the dependent variable.
        Furthermore some of my Independent / (control-) variables became significant, too.

        What do you think? May this be a solution?

        Thank you in advance!

        Comment


        • #5
          Hello guys

          This is the first time I use Stata, and I need to estimate discretionary accruals by the Modified Jones model. Initially, I calculated the total accruals and the other variables: 1 / l.assets, d.saletotal / l.assets and ppegtgross / l.assets, and with all these data I regressed.

          Now I do not know how to give continuity. I need to do the regression by sector and year, but I do not know how to do that. I need to calculate NA and DA. I have the equations but I do not know how to do it in Stata.
          If anyone can help me by showing you the step by step to do this so that I can learn. Sorry for my lack of knowledge, because this is the first time I work with this.
          Thank you!

          This is what I've done so far.




          . import excel "......xls", sheet("Sheet1") firstrow

          . xtset id year, yearly
          panel variable: id (unbalanced)
          time variable: year, 1999 to 2016, but with gaps
          delta: 1 year

          .
          . gen TA = ( netincome - cashop) / l.assets
          (915 missing values generated)

          . gen B0 = 1 / l.assets
          (915 missing values generated)

          . gen B1 = d.saletotal / l.assets
          (915 missing values generated)

          . gen B2 = ppegtgross / l.assets
          (915 missing values generated)

          . reg TA B0 B1 B2, noconstant

          Source | SS df MS Number of obs = 5886
          -------------+------------------------------ F( 3, 5883) = 2241.53
          Model | 2114.1642 3 704.721401 Prob > F = 0.0000
          Residual | 1849.57669 5883 .314393453 R-squared = 0.5334
          -------------+------------------------------ Adj R-squared = 0.5331
          Total | 3963.74089 5886 .673418432 Root MSE = .56071

          ------------------------------------------------------------------------------
          TA | Coef. Std. Err. t P>|t| [95% Conf. Interval]
          -------------+----------------------------------------------------------------
          B0 | -10.31728 .4547222 -22.69 0.000 -11.2087 -9.425858
          B1 | .0966327 .0022241 43.45 0.000 .0922726 .1009928
          B2 | -.1178709 .0068262 -17.27 0.000 -.1312528 -.104489
          ------------------------------------------------------------------------------


          Comment


          • #6
            Andre:
            welcome to this forum.
            Your questions look similar but not identical to the one that started this thread: for the future, please consider starting a more informative thread (Modified Jones Model; by the way, I have no idea about what it is ans probably more tha one lister share my impression. Tht's why the FAQ recommend to report full reference of the literature you're familiar with, that should be legally unknown to other listers. as Stata forum is multidisciplinary).
            That said, I fear that nobody on this list (not me, for instance) can delve into the matter as to write a sort of teaching note; anyway some comments can be useful:
            - you seem to have a panel dataset. You were correct in -xtset-ting your data, but you do not say if you're dealing with a N>T panel dataset (= go -xtreg-) or with a T>N panel dataset (go -xtgls-);
            - you report (for the future, as recommended by the FAQ, use CODE delimiters to share what you typed and what Stata gave you back. Thanks) the results of an OLS (-regress-). Please note that rarely -regress- outperforms -xtreg- (or -xtgls-) when it comes to panel data analysis and, even if the were the case, standard errors of your (pooled) OLS should be clustered on -panelid-, since your observation are not independent due to the panel structure of your dataset. Be also cautious in invoking the -nocostant- option (see -regress- entry in Stata .pdf manual).
            Kind regards,
            Carlo
            (StataNow 18.5)

            Comment

            Working...
            X