Announcement

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

  • Generating a new variable which indicates the intercept of a panel data regression

    Hello Statalist,

    I’m currently writing my Master thesis and for this I want to run a CAPM model analysis. This mean that I run a regression with my y variable being the excess return of a fund and my x variable being the market return (MktRF) to explain this return. The intercept of this regression is the alpha.
    I managed to do all the regressions and autocorrelation correction and so on but I am stuck in how to display this alpha for each fund and every point in time.. I do have the alpha for the whole dataset but I need the alpha for each firm in each point in time. I would like to have the alpha as a new variable.
    My dataset is indicated as panel data with time from month 1 until month 144 and _j indicated the fund (254 funds in total).
    In tried to use:
    Code:
    rangestat (reg) excessReturn MktRF, interval(time 1 144) by(_j)
    This gives me outcomes for all coefficients and their standard errors but it does not show any data for the last 6 months (time = 139 - time = 144).
    How am I using the rangestat command wrong and how can correct it?

    Thanks in advance!


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long time int _j float excessReturn double(MktRF b_cons se_cons)
      1 1   3.4313195   6.570201347971683   .35350237997716044 .20565141267720752
      2 1   1.9142033   .5186172982354644    .3391205967083669 .20624478759303932
      3 1   3.3306024  4.0563810082554586    .3310321150147647 .20696305496817674
      4 1    .3233347   5.510018985513227    .3395978101555059 .20721177560564824
      5 1    -5.73483  -3.681738716963189    .3907701493226293 .20633361123188315
      6 1    .3771338 -.21095529723825868    .3954795577849843 .20818537363527115
      7 1    .7660426   .9906268306971295   .39720632996819244 .20985773540862096
      8 1    2.751279  2.6875687659407497   .38988456996322485  .2112126381550026
      9 1    1.081046   .6623044480024993   .38642622140161303  .2126489460635372
     10 1   4.5625215   3.810545725607125   .36864943070405115 .21294333686088482
     11 1   1.3754038  3.9593756116656884   .36897502251279907 .21407888833056593
     12 1   4.2689695   3.261843575418995    .3541744180985757  .2141343327178002
     13 1   1.8633695   .5899764911083305   .34027771206457386  .2149670205805923
     14 1    .3439541  -.4844388558264542   .33492045939771065 .21646759429837933
     15 1    5.976808  3.7749743628698393   .31131736464170184  .2152742914153149
     16 1    2.114755  5.6485558338629485    .3155813640902164 .21661632240505277
     17 1    1.537313  1.5264854925900049   .31209754071439766 .21819717004271155
     18 1  -4.1135497 -.14685397026493285   .35162093174785025 .21700008883936028
     19 1   -4.044706  -2.224207359577356    .3730686675074972 .21743520575479758
     20 1   1.6258082 -2.0848590545135464    .3593862547836109 .21940673042670214
     21 1   -.7825535   5.090026449195503    .3918594713419362 .21688727490529086
     22 1    .6654124   4.411987361769352    .4017476220973585 .21750790116079544
     23 1   -5.530541  -4.087175863382868    .4702724983125383 .21337700352420658
     24 1   -.6787956  -2.117096565132858    .4699461999464295 .21527386967857487
     25 1   -9.812924   -10.1243459526008    .5313073733485241 .21308027454386033
     26 1   -2.018161   2.025429246078597    .5457583595730429 .21326349937438105
     27 1  -2.3376997    .302916488504424    .5706851480544226 .21400028328592324
     28 1   2.5014765   4.369607258504055    .5809838895910156 .21566556608857268
     29 1  -.54372156   .8593395035759361    .5901296340318849 .21668220749692071
     30 1   -8.949764  -8.801919374054158    .6199050438998849  .2142284388401792
     31 1   1.5445815 -3.7854536799009804    .5920436814872879 .21638641389477864
     32 1   2.8799124  -4.347011213571957    .5313326230094856  .2155323656773753
     33 1   -5.682393  -14.50341958257651    .5329529499048269 .21988854424951917
     34 1   -8.658254  -20.15399085844879    .5759747859742381  .2249380118999789
     35 1   -5.920643  -7.090934634375736    .6418852982297026 .22364923234111392
     36 1   1.1236928   7.486748838871025    .6678156862688651 .22305029579884095
     37 1  -3.5461175 -10.184621776195103    .6525181553275411 .22457267008983872
     38 1   -5.320306   -9.80886494084573    .6563356539211326 .22652777374471456
     39 1  -.07177171   7.343007267961397    .7370794649141169 .22338598387168518
     40 1    9.086434  13.697169747136863    .6185592958314533 .22424660631305385
     41 1   2.9767804  13.805404059458237    .6547066258495181 .22290272762923116
     42 1   -.3096769 -1.8684022038567494    .6525247880624585 .22465400556959342
     43 1    5.147467  10.415684664921098    .6689914460459716 .22639901404733187
     44 1    .5499868   5.578260613207546    .6567832621866844  .2313492460410619
     45 1    3.323418   5.545981403153075    .6435478600465595  .2333854689664006
     46 1   -.9583665  -1.844591903306665    .6491172134678874 .23458445736224345
     47 1   4.3500886   3.074506495697655    .6442790058504914  .2365729006288278
     48 1    5.788769   .8726322589194022     .597550172957894 .23616530287523418
     49 1   -.5860302  -5.154848928384736    .5655700199975979 .23546097933753107
     50 1   -.5913614 -2.0475895073944805     .581275681897035  .2385430037738173
     51 1    7.990909   6.402261008272434    .5781750374981318   .232150318620279
     52 1  -1.3685484 -1.6617913204062789    .5753075717381372 .23403231240543962
     53 1   -5.119522 -11.305645161290322    .6095596543352233 .23878107942339824
     54 1 -.023768056  -.9493184130213631     .621486240930866 .24109455226510984
     55 1    6.131919  12.614253713368125    .6194559703294886 .24306929447524753
     56 1  -1.0332263  -4.130742103067764    .6270973137097556  .2454949233477527
     57 1   2.2735846  12.435541731669266      .59758394962489 .24173454969811065
     58 1    2.168696  5.0213494344014835    .6039009269450184 .24368516685605313
     59 1    .3916414 -7.5935793490783405    .5839284940830943 .24193301931797723
     60 1   4.6875963   9.239119650922453     .584594630651664  .2431337815812606
     61 1    1.776478   3.809962580452029    .5616590939802331 .24859169183377292
     62 1   2.1017292  3.0608649941995356    .5671815187524726  .2517729295876278
     63 1  -1.6896768  -.1509740400607419    .5801286307712639  .2526164771315568
     64 1   3.6169455    8.59010073519016    .5872174013976474 .25169161277903657
     65 1    .7442169   -3.00522344961891     .572025488765415  .2553592313602969
     66 1   -3.016545 -2.0641884163460538    .6180476505060384 .25490247099290886
     67 1    .7408155 -3.2847112031762475    .6105541657427231  .2586630608925525
     68 1   -9.374828 -10.141754453911695    .7841633345131274 .25087918540879595
     69 1  -2.3113217  -10.87364653871794    .7444904653291732 .26402124963414664
     70 1    6.016758   11.33250866355281    .7628770390109965  .2608072268337356
     71 1    .3383387  -4.782158525884761    .7767556684816099  .2644500702465395
     72 1    2.444071  -2.156481069042316     .743088970885756 .26679644700113814
     73 1    2.858945   5.781239456149136    .7164636333043353  .2750511335970362
     74 1    3.107944   6.485234126382785     .722960018351928 .27813081873807677
     75 1   1.1063871 .017628262826282493    .7230907691375275 .28059872100555966
     76 1    .9021363  -2.222971956995715    .7239006483949828  .2831093711140455
     77 1   -4.976072 -11.572818903591683    .7325435416183075  .2879911984583329
     78 1    5.901498   7.275331230283912    .7323283680616866 .29617158939431215
     79 1    4.928861   .5244214876033058    .7138509778351413 .29665379536969183
     80 1     1.27535  4.6381499552736445     .723993215854779  .3022300412113062
     81 1    .6970038  3.6048994675355637    .7238738496460178 .30583252791385107
     82 1   -.4700159  1.6766206896551723    .7501758069436129 .30899577934651346
     83 1     .898728  2.3141006415706884    .7972938907795385 .30875389111007173
     84 1  -.10828493   3.417696515319588    .7959908226310913 .31231006208430306
     85 1    2.972673   6.500388349514564    .7863421725164186 .31495368013391156
     86 1   2.1774848 -2.4125408878504673    .7699663710487088  .3137638037894099
     87 1    4.258314  -.5349591805298829     .739893215079617 .31733899556595546
     88 1   1.1382352   4.309240289561765    .7612785683989412 .32049410549382534
     89 1    1.332525  1.0344705525657543    .7325405196911328  .3226497123411331
     90 1  -2.3537145  -4.651680801258683    .7329147274386841 .32908987229672615
     91 1   4.2192717   7.578349507115185    .7330857216981433  .3321648346392158
     92 1  -1.1918187   -.701020138285412    .7152779464779766 .34017464086778393
     93 1   1.4287045   7.235187094817455    .7099087759077541  .3372394790477181
     94 1   4.2183423   4.474575801264279    .6946646684100097  .3353637217330706
     95 1   1.1389917  1.3318687673772014    .6939020345862775 .33976843869161055
     96 1   1.9491826    2.41527090325674    .6912342251131556  .3448449249997338
     97 1   -.6478872  -2.981738814906201    .6329366296591406 .33353787828000303
     98 1    3.783163   7.497317749750341    .6342778069241617  .3373341440713437
     99 1   1.1449273  -.5192681598722184      .57042851142902  .3433231188754469
    100 1  -.22021325  1.7943086012541234    .7332986726483806   .345916746324789
    101 1   4.0728974   .7174371641844866    .6728547544213608  .3517425622746486
    102 1    .4089729 -.10529083226162039    .7036963161937798 .36006048141405866
    103 1   -2.914174  -4.043232574289996    .7824176393748874  .3748802001200998
    104 1     3.31851 -.05109166728721426    .7362748657446665 .38522226197043974
    105 1    .6528403 -3.6749977163736016    .7241754954377815  .4015933183243954
    106 1     -.59909 -2.6850184589734427    .8634373673590023  .4116603773421031
    107 1    3.737088  2.0980135367856145     .909084374311657 .43005390022896833
    108 1   -.4308163 -3.6283296597603494    .8617137662517407  .4397465517429026
    109 1    7.956588  -.3625403908929383     .670471371348117  .4210054106390282
    110 1    6.226552    6.12579979724071    .5574321563852648  .4145267173806968
    111 1   1.7588414 -2.2107614666607116    .4581650733207525  .4224443042268231
    112 1   -.3803908   5.029564045361592    .5060598847235278  .4237521506646076
    113 1    1.331393 -.16490532412564063    .4881442766080353  .4301587599250098
    114 1  -2.9241464 -2.8643413626978664   .48579880549553955   .444341026050325
    115 1     4.09724  2.3504571248423707     .465362578191262  .4547026298081328
    116 1   -9.646673  -6.161107769423559    .6381795770051415  .4198770240221363
    117 1    .7412031  -4.264122218768042    .5483513019671114  .4315406350193696
    118 1    6.633726   6.081225901463763   .49295812804001593 .45811785785632625
    119 1    3.569316 -1.4614255290226108     .284783618324091 .44516289283996857
    120 1   -3.665285  -1.890955456045251   .28912716293139407 .45204915737685386
    121 1   -4.809021  -6.445245788456227    .7010224444315163   .478800126149265
    122 1  -1.0332164 -1.7077839996328086    .7704039232574569  .5163087904357966
    123 1   -1.821641  7.0651411206777475    .6715621502192171 .41257333736961305
    124 1   1.7624265   2.430200969590128    .6479592045769714  .4386482657872737
    125 1   2.9863305  -.3983627915056238   .44655908248103926 .39811582005432966
    126 1   -3.485012  -4.995463862161557    .5200948773542646  .4769426989851909
    127 1    2.471764   4.449267427236794    .5281790831018822 .49645071706447885
    128 1    .3967934   .7834256814214746    .5208930855322089  .5159625798020995
    129 1    .8068931   .9543554006968638    .4013520341685315  .5481775541327157
    130 1  -2.4711914  -3.047644856480656   .33873196254193383  .5861546718519518
    131 1   -.9960812 -2.4413229501516724    .2012894089285857   .722018907131668
    132 1   4.1758833   4.685501578476181   .10607260889104309   .688601685231692
    133 1    .9909721  2.9067997155724106   .15571666487905267  .7398312522691802
    134 1    2.979244    .648301886792453 -.015044632011580905  .9864600202015483
    135 1    2.542118    4.31817686623721  -.02564898030755014 1.1097370417797363
    136 1   2.0016153  4.7598075569115235  -.14279737849051277 1.2392975386351612
    137 1   1.9981813   5.200115869017633  -.11150424207870274  .8764189107004015
    138 1  -3.1673026  -.6658108770210682  -.40795075463735464  1.036514919012721
    139 1  -.05839239   3.674964813511611                    .                  .
    140 1    .3911339  .11648518204911107                    .                  .
    141 1     2.77661  2.6752184527317118                    .                  .
    142 1   2.2237444   .5837082481254259                    .                  .
    143 1   -2.966014 .001090689966857683                    .                  .
    144 1   1.4245106  1.4994530822062107                    .                  .
    end

  • #2
    I don't understand your post. The -dataex- example you show is (part of) your output? It already contains b_cons and se_cons variables. But I can't reproduce your results on my setup. When I run your -dataex-, and then -drop *_cons- and run
    Code:
    rangestat (reg) excessReturn MktRF, interval(time 1 144) by(_j)
    I get results for all observations except times = 142 through 144. The omission of those 3 is, of course, correct, because there are not enough observations in specified range to do the regression.

    Moreover, the values for b_cons and se_cons I get are rather different from the numbers you are showing your -dataex-. Do you have the most updated version of -rangestat-?

    Code:
    . which rangestat
    c:\ado\plus\r\rangestat.ado
    *! 1.1.1                        09may2017
    *! 1.1.0                        16apr2017
    *! 1.0.0            29mar2016 
    *! Robert Picard    [email protected]
    *! Nicholas J. Cox  [email protected] 
    *! Roberto Ferrer   [email protected]
    There were some bugs in the earlier versions.

    Comment


    • #3
      Sorry, I see what I did wrong. I'm trying to test a 4 factor model instead of the 1 factor model I displayed. I thought it was better to post the 1 factor model to keep a clean overview, but of course this changes the outcomes. Since you are saying the omission of the last variables is correct I think I used the correct code after all and will have to go through the theory once again. Sorry for the apparently unnecessary question and thank you for the answer!

      Comment


      • #4
        And, indeed, if you used a four factor model, you can expect the last 6 observations to yield no result, because there will not be enough observations in the specified interval to do a regression with that many factors.

        Comment

        Working...
        X