Announcement

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

  • rolling regression with predicted values and sum.

    Dear All, The purpose of this thread is to obtain "Financial Statement Comparability" measure, e.g., “The Benefits of Financial Statement Comparability.” DeFranco, Gus, S.P. Kothari and Rodrigo Verdi. Journal of Accounting Research Vol. 49, No. 4 (2011): 895-931.
    A sample data is here: (The frequency is quarterly.)
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int Stkcd str10 Accper double(ret earn) float ind
    1 "2011-03-31"   .018365444615483284  43.653831481933594 1
    1 "2011-06-30"    .06156753748655319    84.4366226196289 1
    1 "2011-09-30"  -.060339417308568954   130.1930389404297 1
    1 "2011-12-31"  -.028054753318428993  126.43800354003906 1
    1 "2012-03-31"   .007696649990975857  43.763031005859375 1
    1 "2012-06-30"   -.03500852733850479    85.3490982055664 1
    1 "2012-09-30"     -.133904829621315  133.20423889160156 1
    1 "2012-12-31"    .22919052839279175  200.84527587890625 1
    1 "2013-03-31"     .2559305727481842  43.727725982666016 1
    1 "2013-06-30"   -.19962303340435028   73.05847930908203 1
    1 "2013-09-30"    .19157494604587555  143.10939025878906 1
    1 "2013-12-31"    .03114444576203823  156.40042114257812 1
    1 "2014-03-31"   -.12081636488437653   50.32978820800781 1
    1 "2014-06-30"    .11934009939432144   98.22659301757813 1
    1 "2014-09-30"   .023208416998386383  138.61422729492187 1
    1 "2014-12-31"     .5621297359466553  170.93023681640625 1
    1 "2015-03-31"  -.005682411603629589   31.10454559326172 1
    1 "2015-06-30"    .11752037703990936   64.38182830810547 1
    1 "2015-09-30"    -.2785419225692749   85.26872253417969 1
    1 "2015-12-31"    .14299383759498596  145.67147827148437 1
    1 "2016-03-31"   -.11259397864341736   35.47425842285156 1
    1 "2016-06-30" -.0041998825035989285   80.73863983154297 1
    1 "2016-09-30"    .04252886399626732  125.30912780761719 1
    1 "2016-12-31"  .0033079085405915976  145.11129760742187 1
    1 "2017-03-31"   .007692847400903702  39.769412994384766 1
    1 "2017-06-30"   .023991048336029053   79.73189544677734 1
    1 "2017-09-30"    .20033949613571167  118.79291534423828 1
    2 "2011-03-31"    .05717777833342552  14.954622268676758 1
    2 "2011-06-30"  -.015309927053749561    38.6645622253418 1
    2 "2011-09-30"   -.14319486916065216   50.20100021362305 1
    2 "2011-12-31"   .031767942011356354    165.507568359375 1
    2 "2012-03-31"    .10843338072299957    21.1660213470459 1
    2 "2012-06-30"    .07608681917190552   56.58559799194336 1
    2 "2012-09-30"   -.04063301905989647   71.25907897949219 1
    2 "2012-12-31"    .20047396421432495  191.93280029296875 1
    2 "2013-03-31"    .06324122101068497  18.265546798706055 1
    2 "2013-06-30"   -.07048974186182022   51.22624588012695 1
    2 "2013-09-30"    -.0730976089835167    78.4146728515625 1
    2 "2013-12-31"    -.1204819530248642   206.6357879638672 1
    2 "2014-03-31"    .00747232511639595  21.033597946166992 1
    2 "2014-06-30"    .07927099615335465   69.99187469482422 1
    2 "2014-09-30"    .11003623157739639      94.80224609375 1
    2 "2014-12-31"     .5141599774360657  216.60020446777344 1
    2 "2015-03-31"  -.005754666868597269   6.718979835510254 1
    2 "2015-06-30"     .0506519190967083   50.52988815307617 1
    2 "2015-09-30"   -.09306689351797104   67.49441528320313 1
    2 "2015-12-31"       .91908860206604  209.54843139648437 1
    2 "2016-12-31"    -.2147500216960907  111.40367889404297 1
    2 "2017-03-31"  .0014597486006096005   5.550509929656982 1
    2 "2017-06-30"     .2133135050535202   50.23381423950195 1
    2 "2017-09-30"    .08681178838014603    61.0202751159668 1
    4 "2011-03-31"    .09468340128660202  1.3481107950210571 1
    4 "2011-06-30"   -.06904404610395432   2.627516508102417 1
    4 "2011-09-30"   -.15240375697612762   4.367613792419434 1
    4 "2011-12-31"   -.22211547195911407  10.526122093200684 1
    4 "2012-03-31"  .0049445428885519505  1.7107731103897095 1
    4 "2012-06-30"    .04181978479027748  2.0242059230804443 1
    4 "2012-09-30"   -.04132254794239998   4.945676803588867 1
    4 "2012-12-31"   .007388699799776077   11.45964527130127 1
    4 "2013-03-31"    .16625899076461792   4.137348651885986 1
    4 "2013-06-30"     .0482185073196888      5.187255859375 1
    4 "2013-09-30"    .27300041913986206   8.921060562133789 1
    4 "2013-12-31"   -.08483946323394775   5.422473430633545 1
    4 "2014-03-31"    .09613719582557678 -3.4672744274139404 1
    4 "2014-06-30"    .08692249655723572  -4.418781280517578 1
    4 "2014-09-30"    .34870338439941406  -3.443899154663086 1
    4 "2014-12-31"    -.1682698130607605   9.939173698425293 1
    4 "2015-03-31"     .5401414632797241  -1.343976378440857 1
    4 "2015-06-30"     .6055042743682861  2.1902618408203125 1
    4 "2015-09-30"   -.34129878878593445   2.301856279373169 1
    4 "2015-12-31"     .8099364042282105   3.219851016998291 1
    4 "2016-03-31"   -.19760337471961975  -.7404028177261353 1
    4 "2016-12-31"    .19861237704753876  12.625322341918945 1
    4 "2017-03-31"   -.19821792840957642 -.44819581508636475 1
    4 "2017-06-30"    -.2874999940395355 -1.9039255380630493 1
    4 "2017-09-30"   -.06159806624054909 -3.8107426166534424 1
    5 "2011-03-31"    .10354173183441162  -1.874783992767334 1
    5 "2012-09-30"   -.05315576493740082  -4.864426612854004 1
    5 "2012-12-31"    .04210561141371727   8.450836181640625 1
    5 "2013-03-31"   -.09090884774923325  -3.400902032852173 1
    5 "2013-06-30"   -.15555503964424133  -9.096631050109863 1
    5 "2013-09-30"    .07894653081893921 -13.911046028137207 1
    5 "2013-12-31"   .016261205077171326  -18.82607650756836 1
    5 "2014-03-31"   .012000244110822678 -3.7982757091522217 1
    5 "2014-06-30"   -.10671987384557724 -10.902318954467773 1
    5 "2014-09-30"     .7477884292602539 -15.460854530334473 1
    5 "2014-12-31"   .037974897772073746  11.951415061950684 1
    5 "2015-09-30"   -.32679733633995056 -3.5546228885650635 1
    5 "2015-12-31"      .624596357345581  -9.562151908874512 1
    5 "2016-03-31"   -.23605568706989288  -.6041566133499146 1
    5 "2016-06-30"   -.01694917492568493    16.1798038482666 1
    5 "2016-09-30"  -.027851246297359467   17.77695083618164 1
    5 "2016-12-31"   -.07776278257369995  15.074273109436035 1
    5 "2017-03-31"   -.07396496832370758 -1.3565131425857544 1
    5 "2017-06-30"   -.16293977200984955  -2.272408962249756 1
    5 "2017-09-30"  -.036259040236473083 -1.9964791536331177 1
    6 "2011-03-31"    .12482082098722458  10.144095420837402 2
    6 "2011-06-30"  -.028611034154891968  22.365764617919922 2
    6 "2011-09-30"    -.1290881633758545   48.10047149658203 2
    6 "2011-12-31"   -.18972378969192505    86.7474594116211 2
    end
    For each firm, I need to do the following: (How can I use LaTeX in this forum?)
    Click image for larger version

Name:	fsc.png
Views:	1
Size:	29.0 KB
ID:	1433302



    Any suggestions are appreciated. In case I did not make myself clear, please feel free to raise your questions, Thanks.
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    answered in a following thread.

    Comment


    • #3
      Dear Robert, I'd like to thank you again for your previous answers to this question (https://www.statalist.org/forums/for...fter-rangestat).
      Click image for larger version

Name:	FSV.png
Views:	1
Size:	52.0 KB
ID:	1563459




      Later, I recognize that the financial statement comparability (FSC) measure from equation (4) can be calculated as equation (5). As such, I think that I can do the following to (greatly) speed up the whole estimation process, say, 3000 firms (15 industries) and 80 quarterly observations (20 years). I wonder if you have time to have a look at my preliminary code (below) and share your comment? Thanks.
      Code:
      clear all
      set seed 3123
      
      * demonstration dataset, 50 firms over 40 quarters in 10 industry
      set obs 3000
      gen id = _n
      gen industry = runiformint(1,15)
      expand 80
      bysort id: gen qdate = yq(1999,4) + _n
      format %tq qdate
      gen returns = runiform()
      gen earnings = runiform()
      gen year = year(dofq(qdate))
      
      // ssc install etime
      etime, start
      
      forvalues t = 2004(1)2019 {
        preserve    
        
        keep if inrange(year,`t'-4,`t'-1)
        // ssc install rangestat
        rangestat (reg) earnings returns, interval(year . .) by(id)
        drop reg_r2 reg_adj_r2 se_returns se_cons
      
        // Andrew Musau
        egen group = group(industry qdate), label
        tempfile raw
        save `raw'
        rename (*) (*2)
        ren group2 group
        joinby group using `raw'
        *bys group: drop if id>=id2
        *sort id id2 qdate
      
        gen CompAcct_River = -abs((b_cons - b_cons2) + (b_returns - b_returns2)*returns)
      
        collapse (mean) CompAcct_River, by(id id2)
        gen year = `t'
        *list id id2 year CompAcct_River, sepby(id)
        save "FSC-River-`t'.dta", replace
      
        restore
      }
      
      etime
      Last edited by River Huang; 14 Jul 2020, 21:43.
      Ho-Chuan (River) Huang
      Stata 17.0, MP(4)

      Comment

      Working...
      X