Dear All,
- I asked a (probably too complicated) question (or I didn't make myself clear) in this thread https://www.statalist.org/forums/for...values-and-sum but got no response.
- I figure out that I can use -rangestat- command to estimate equation (1), for each firm-year, using 8 previous quarters (2 years) of data as below (Note that I now use a more complete data set).
-
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int Stkcd double(ret earn) float(year ind) double(b_ret b_cons) 1 .007696649990975857 43.763031005859375 2012 1 . . 1 -.03500852733850479 85.3490982055664 2012 1 . . 1 -.133904829621315 133.20423889160156 2012 1 . . 1 .22919052839279175 200.84527587890625 2012 1 . . 1 .2559305727481842 43.727725982666016 2013 1 250.3708536493786 111.53574507155234 1 -.19962303340435028 73.05847930908203 2013 1 250.3708536493786 111.53574507155234 1 .19157494604587555 143.10939025878906 2013 1 250.3708536493786 111.53574507155234 1 .03114444576203823 156.40042114257812 2013 1 250.3708536493786 111.53574507155234 1 -.12081636488437653 50.32978820800781 2014 1 81.57574377583794 106.39385202411387 1 .11934009939432144 98.22659301757813 2014 1 81.57574377583794 106.39385202411387 1 .023208416998386383 138.61422729492187 2014 1 81.57574377583794 106.39385202411387 1 .5621297359466553 170.93023681640625 2014 1 81.57574377583794 106.39385202411387 1 -.005682411603629589 31.10454559326172 2015 1 99.98228492552718 98.51540828862993 1 .11752037703990936 64.38182830810547 2015 1 99.98228492552718 98.51540828862993 1 -.2785419225692749 85.26872253417969 2015 1 99.98228492552718 98.51540828862993 1 .14299383759498596 145.67147827148437 2015 1 99.98228492552718 98.51540828862993 1 -.11259397864341736 35.47425842285156 2016 1 130.3293235098682 88.94040238355862 1 -.0041998825035989285 80.73863983154297 2016 1 130.3293235098682 88.94040238355862 1 .04252886399626732 125.30912780761719 2016 1 130.3293235098682 88.94040238355862 1 .0033079085405915976 145.11129760742187 2016 1 130.3293235098682 88.94040238355862 1 .007692847400903702 39.769412994384766 2017 1 114.81183759595241 90.49110181300429 1 .023991048336029053 79.73189544677734 2017 1 114.81183759595241 90.49110181300429 1 .20033949613571167 118.79291534423828 2017 1 114.81183759595241 90.49110181300429 2 .10843338072299957 21.1660213470459 2012 1 . . 2 .07608681917190552 56.58559799194336 2012 1 . . 2 -.04063301905989647 71.25907897949219 2012 1 . . 2 .20047396421432495 191.93280029296875 2012 1 . . 2 .06324122101068497 18.265546798706055 2013 1 431.4028328552355 48.09628127797376 2 -.07048974186182022 51.22624588012695 2013 1 431.4028328552355 48.09628127797376 2 -.0730976089835167 78.4146728515625 2013 1 431.4028328552355 48.09628127797376 2 -.1204819530248642 206.6357879638672 2013 1 431.4028328552355 48.09628127797376 2 .00747232511639595 21.033597946166992 2014 1 -39.45780408848296 87.64365644422733 2 .07927099615335465 69.99187469482422 2014 1 -39.45780408848296 87.64365644422733 2 .11003623157739639 94.80224609375 2014 1 -39.45780408848296 87.64365644422733 2 .5141599774360657 216.60020446777344 2014 1 -39.45780408848296 87.64365644422733 2 -.005754666868597269 6.718979835510254 2015 1 165.35962827091322 84.07729217175718 2 .0506519190967083 50.52988815307617 2015 1 165.35962827091322 84.07729217175718 2 -.09306689351797104 67.49441528320313 2015 1 165.35962827091322 84.07729217175718 2 .91908860206604 209.54843139648437 2015 1 165.35962827091322 84.07729217175718 2 -.2147500216960907 111.40367889404297 2016 1 206.61297689778746 51.23589325024565 2 .0014597486006096005 5.550509929656982 2017 1 130.41655255662448 72.0240205265508 2 .2133135050535202 50.23381423950195 2017 1 130.41655255662448 72.0240205265508 2 .08681178838014603 61.0202751159668 2017 1 130.41655255662448 72.0240205265508 4 .0049445428885519505 1.7107731103897095 2012 1 . . 4 .04181978479027748 2.0242059230804443 2012 1 . . 4 -.04132254794239998 4.945676803588867 2012 1 . . 4 .007388699799776077 11.45964527130127 2012 1 . . 4 .16625899076461792 4.137348651885986 2013 1 -26.09586991637258 5.118780908325447 4 .0482185073196888 5.187255859375 2013 1 -26.09586991637258 5.118780908325447 4 .27300041913986206 8.921060562133789 2013 1 -26.09586991637258 5.118780908325447 4 -.08483946323394775 5.422473430633545 2013 1 -26.09586991637258 5.118780908325447 4 .09613719582557678 -3.4672744274139404 2014 1 6.531478251813688 5.136851663594566 4 .08692249655723572 -4.418781280517578 2014 1 6.531478251813688 5.136851663594566 4 .34870338439941406 -3.443899154663086 2014 1 6.531478251813688 5.136851663594566 4 -.1682698130607605 9.939173698425293 2014 1 6.531478251813688 5.136851663594566 4 .5401414632797241 -1.343976378440857 2015 1 -13.709171538018968 4.097548559835706 4 .6055042743682861 2.1902618408203125 2015 1 -13.709171538018968 4.097548559835706 4 -.34129878878593445 2.301856279373169 2015 1 -13.709171538018968 4.097548559835706 4 .8099364042282105 3.219851016998291 2015 1 -13.709171538018968 4.097548559835706 4 -.19760337471961975 -.7404028177261353 2016 1 -2.163699481616878 1.1570657293913968 4 .19861237704753876 12.625322341918945 2016 1 -2.163699481616878 1.1570657293913968 4 -.19821792840957642 -.44819581508636475 2017 1 .1511543888455824 3.0014589590255905 4 -.2874999940395355 -1.9039255380630493 2017 1 .1511543888455824 3.0014589590255905 4 -.06159806624054909 -3.8107426166534424 2017 1 .1511543888455824 3.0014589590255905 5 -.05315576493740082 -4.864426612854004 2012 1 . . 5 .04210561141371727 8.450836181640625 2012 1 . . 5 -.09090884774923325 -3.400902032852173 2013 1 . . 5 -.15555503964424133 -9.096631050109863 2013 1 . . 5 .07894653081893921 -13.911046028137207 2013 1 . . 5 .016261205077171326 -18.82607650756836 2013 1 . . 5 .012000244110822678 -3.7982757091522217 2014 1 -4.9121789231354285 -7.074253943416227 5 -.10671987384557724 -10.902318954467773 2014 1 -4.9121789231354285 -7.074253943416227 5 .7477884292602539 -15.460854530334473 2014 1 -4.9121789231354285 -7.074253943416227 5 .037974897772073746 11.951415061950684 2014 1 -4.9121789231354285 -7.074253943416227 5 -.32679733633995056 -3.5546228885650635 2015 1 -9.37708624400568 -7.297881922532834 5 .624596357345581 -9.562151908874512 2015 1 -9.37708624400568 -7.297881922532834 5 -.23605568706989288 -.6041566133499146 2016 1 -10.636265770230278 -3.468202495435589 5 -.01694917492568493 16.1798038482666 2016 1 -10.636265770230278 -3.468202495435589 5 -.027851246297359467 17.77695083618164 2016 1 -10.636265770230278 -3.468202495435589 5 -.07776278257369995 15.074273109436035 2016 1 -10.636265770230278 -3.468202495435589 5 -.07396496832370758 -1.3565131425857544 2017 1 -11.181358473514141 5.771674602644399 5 -.16293977200984955 -2.272408962249756 2017 1 -11.181358473514141 5.771674602644399 5 -.036259040236473083 -1.9964791536331177 2017 1 -11.181358473514141 5.771674602644399 6 .3439035415649414 20.807355880737305 2012 2 . . 6 .03629857674241066 49.515106201171875 2012 2 . . 6 -.08083932846784592 61.64518737792969 2012 2 . . 6 .2344132512807846 122.11065673828125 2012 2 . . 6 -.09090826660394669 9.778822898864746 2013 2 -11.936866884032497 65.11247993671472 6 .01617056131362915 46.89581298828125 2013 2 -11.936866884032497 65.11247993671472 6 .08450716733932495 62.71464157104492 2013 2 -11.936866884032497 65.11247993671472 6 .06709986180067062 111.9146499633789 2013 2 -11.936866884032497 65.11247993671472 6 .09330663084983826 4.537078857421875 2014 2 53.17936131727416 56.61356288990416 6 -.12177072465419769 6.690219402313232 2014 2 53.17936131727416 56.61356288990416 6 .27947667241096497 38.55535888671875 2014 2 53.17936131727416 56.61356288990416 6 .20307159423828125 64.77758026123047 2014 2 53.17936131727416 56.61356288990416 6 .24822726845741272 22.119033813476563 2015 2 103.76637417992296 36.34613070238843 6 .553745687007904 22.59101104736328 2015 2 103.76637417992296 36.34613070238843 6 -.30729520320892334 15.699004173278809 2015 2 103.76637417992296 36.34613070238843 6 .2244689017534256 34.57742691040039 2015 2 103.76637417992296 36.34613070238843 6 -.27888813614845276 3.213345527648926 2016 2 28.40571198403756 22.027532049221797 6 -.09731023758649826 9.462743759155273 2016 2 28.40571198403756 22.027532049221797 6 .31071972846984863 12.038106918334961 2016 2 28.40571198403756 22.027532049221797 6 -.0217384435236454 61.64247512817383 2016 2 28.40571198403756 22.027532049221797 6 -.12381055951118469 8.825848579406738 2017 2 11.115722179453737 21.789849224231453 6 .08592195063829422 23.555709838867188 2017 2 11.115722179453737 21.789849224231453 6 .11804693192243576 29.731189727783203 2017 2 11.115722179453737 21.789849224231453 7 .7538010478019714 .24515913426876068 2012 2 . . 7 .2859620749950409 1.521431803703308 2012 2 . . 7 .037061505019664764 2.824248790740967 2012 2 . . 7 -.05977896973490715 1.247214913368225 2012 2 . . 7 .09053147584199905 -3.462310791015625 2013 2 -2.1052663107087626 1.9948016506233583 7 -.16032932698726654 -.7407301068305969 2013 2 -2.1052663107087626 1.9948016506233583 7 .012075320817530155 11.717114448547363 2013 2 -2.1052663107087626 1.9948016506233583 7 .03504834696650505 6.0797905921936035 2013 2 -2.1052663107087626 1.9948016506233583 7 -.12463978677988052 -2.445725917816162 2014 2 -2.8333893070007967 2.781170036079474 7 -.1225961297750473 -8.686015129089356 2014 2 -2.8333893070007967 2.781170036079474 7 .31164389848709106 -1.8441765308380127 2015 2 30.547386015645596 1.7845285179416073 7 .05386490747332573 14.52142333984375 2016 2 8.499844504551897 -4.507791803006302 end
- The code for the above result is
Code:
rangestat (reg) earn ret, interval(year -2 -1) by(Stkcd) keep Stkcd year ret earn ind b_* dataex, count(130)
- Now, my next step is, say for year 2014, using quarterly data in 2012 and 2013 from Stkcd=1, and coefficients estimates for all firms in the same industry (ind=1, just ignore ind=2 at this moment) in year 2014 (for Stkcd=1, they are b_ret=81.575744 and b_cons=106.39385; for Stck=2, they are b_ret=431.40283 and b_cons=48.096281, and so on) to obtain predicted earn as in equations (2) and (3) as shown in the prior thread. I suspect that this can be done using -rangerun- command by writing a small procedure, but I am unable to do so. Any suggestion is highly appreciated.
Comment