Announcement

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

  • #46
    I am appending new data example as suggested it has more stock_id's. And It contains data on rt instead of ert.

    P.S. I forgot to mention in #44. Apart from generating of average beta, rt and corresponding t-stat of average rt. For each variant and both equal and value weight deciles, i want to form a portfolio which is called HL and equals decile 10 minus decile 1. For this HL also, we need average and corresponding t-stat value.

    Moreover, in another file, i have data on three factors, market, size and value. This data is to be merged in main file. In separate regressions of deciles and HL first on market factor and then on market, size and value factor, i want to generate mean rt of each decile and HL and their corresponding t-stat (newey-west adjusted)

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float stock_id str54 stock int date float(mdate rt) double(beta mcap)
    1 "3M India Ltd."         17136 563  .001986755  .9363791897476034  1704.41
    1 "3M India Ltd."         17167 564   .12273628  .9223737930509442   1913.6
    1 "3M India Ltd."         17198 565  .022899864   .922756816668508  1957.42
    1 "3M India Ltd."         17226 566  -.09570672  .8936533493659552  1770.08
    1 "3M India Ltd."         17257 567   .08442055  .9255302588321866  1919.51
    1 "3M India Ltd."         17287 568   .12479826  .9350681183690134  2159.06
    1 "3M India Ltd."         17318 569   .09339456  .9271015207020946  2360.71
    1 "3M India Ltd."         17348 570  -.13650028   .928254346339326  2038.47
    1 "3M India Ltd."         17379 571  -.04351911  .9836310240772113  1949.76
    1 "3M India Ltd."         17410 572   .04327479  .9891430041241998  2034.13
    1 "3M India Ltd."         17440 573    .2355596  .9751046493064751  2513.29
    1 "3M India Ltd."         17471 574   -.1149907  .9956336356126323  2224.29
    1 "3M India Ltd."         17501 575   .16502912 1.0016201663302253  2591.36
    1 "3M India Ltd."         17532 576   -.1716478 1.0163532769060692  2146.56
    1 "3M India Ltd."         17563 577  .018472841  .9914501373606369  2186.21
    1 "3M India Ltd."         17592 578  -.06211676  .9814122102459226  2050.41
    1 "3M India Ltd."         17623 579  .023679366  .9226485941803548  2098.96
    1 "3M India Ltd."         17653 580 -.006896552  .9157756854647555  2084.49
    1 "3M India Ltd."         17684 581  -.09614138  .9080926389855237  1884.08
    1 "3M India Ltd."         17714 582  -.04035874  .8762961854634894  1808.04
    1 "3M India Ltd."         17745 583  .012305296  .8605383835206916  1830.29
    1 "3M India Ltd."         17776 584  -.11377135  .8680215325174288  1622.06
    1 "3M India Ltd."         17806 585   -.3538787  .8790495453705364  1048.05
    1 "3M India Ltd."         17837 586  -.01537056  .9539156687231287  1031.94
    1 "3M India Ltd."         17867 587  .010861852   .933792486219891  1043.15
    1 "3M India Ltd."         17898 588  .021058315  .9699855719761739  1065.11
    1 "3M India Ltd."         17929 589  -.05462718  .9422987555783494  1006.93
    1 "3M India Ltd."         17957 590 -.016613526  .9449352765119065    990.2
    1 "3M India Ltd."         17988 591    .1656428   .923992991288802  1154.22
    1 "3M India Ltd."         18018 592   .21149717  .9315873561349993  1398.33
    1 "3M India Ltd."         18049 593  .035205025  .8966264545990463  1447.56
    1 "3M India Ltd."         18079 594   .12953307  .8952355982767113  1635.07
    1 "3M India Ltd."         18110 595   .07578629  .9026652138700382  1758.98
    1 "3M India Ltd."         18141 596    .1142848  .9015792779073551  1960.01
    1 "3M India Ltd."         18171 597 -.031409852  .8997408733078569  1898.45
    1 "3M India Ltd."         18202 598   .06058448  .8956781585590297  2013.46
    1 "3M India Ltd."         18232 599  .036534533  .8934226024323634  2087.02
    2 "3P Land Holdings Ltd." 17136 563   .27454546  .6063615825199706    12.62
    2 "3P Land Holdings Ltd." 17167 564  -.13552068  .5882292970802359    10.91
    2 "3P Land Holdings Ltd." 17198 565  -.06105611  .5856696529156193    10.24
    2 "3P Land Holdings Ltd." 17226 566   .13884006  .5735485544392244    11.66
    2 "3P Land Holdings Ltd." 17257 567   .12654321  .5503792292363405    13.14
    2 "3P Land Holdings Ltd." 17287 568  .006849315 .48935011341041157    13.23
    2 "3P Land Holdings Ltd." 17318 569  -.05034013  .8768593708147372    12.56
    2 "3P Land Holdings Ltd." 17348 570  .031518623  .8939266963061522    12.96
    2 "3P Land Holdings Ltd." 17379 571   .08194444  .8576006798129209    14.02
    2 "3P Land Holdings Ltd." 17410 572   .07830552  .8595353596032033    15.12
    2 "3P Land Holdings Ltd." 17440 573  -.08809524  .8098852261235144    13.79
    2 "3P Land Holdings Ltd." 17471 574   2.1840732  .6522657484280153     43.9
    2 "3P Land Holdings Ltd." 17501 575    1.496925  .6172125043576382   109.62
    2 "3P Land Holdings Ltd." 17532 576   -.3904762  .7591263309826475    66.82
    2 "3P Land Holdings Ltd." 17563 577   .05414871  .9427380079566117    70.43
    2 "3P Land Holdings Ltd." 17592 578  -.27804753  .9497029550792229    50.85
    2 "3P Land Holdings Ltd." 17623 579   .01238938  .9893970561286551    51.48
    2 "3P Land Holdings Ltd." 17653 580  -.01923077  .9545370561011615    50.49
    2 "3P Land Holdings Ltd." 17684 581    -.315508 1.0104470351402894    34.56
    2 "3P Land Holdings Ltd." 17714 582  .036458332 1.0851988356528055    35.82
    2 "3P Land Holdings Ltd." 17745 583  -.09045226 1.0786019882311453    32.58
    2 "3P Land Holdings Ltd." 17776 584   -.1160221 1.1083191649820048     28.8
    2 "3P Land Holdings Ltd." 17806 585    -.503125  1.114426134944222    14.31
    2 "3P Land Holdings Ltd." 17837 586   .12201258 1.2837179550512692    16.06
    2 "3P Land Holdings Ltd." 17867 587  .036995515  1.225022704005749    16.65
    2 "3P Land Holdings Ltd." 17898 588  -.02702703  1.212781001580348     16.2
    2 "3P Land Holdings Ltd." 17929 589  -.22222222 1.1640822093216887     12.6
    2 "3P Land Holdings Ltd." 17957 590         .25 1.1842704014702627    15.75
    2 "3P Land Holdings Ltd." 17988 591         .08 1.1992254625286194    17.01
    2 "3P Land Holdings Ltd." 18018 592   .24232805  1.159497689882982    21.13
    2 "3P Land Holdings Ltd." 18049 593   .26064736  1.243023955320111    26.64
    2 "3P Land Holdings Ltd." 18079 594  -.02702703 1.2535683448509727    25.92
    2 "3P Land Holdings Ltd." 18110 595 -.007638889  1.231016487071214    25.72
    2 "3P Land Holdings Ltd." 18141 596 .0020993701 1.2431189335636115    25.78
    2 "3P Land Holdings Ltd." 18171 597  -.04539106 1.2032554684323835    24.61
    2 "3P Land Holdings Ltd." 18202 598   -.0380395 1.2059037350629862    23.67
    2 "3P Land Holdings Ltd." 18232 599   .25931558 1.1872302182477175    29.81
    3 "A B B India Ltd."      17136 563    .0601711  .9734345282698555 15729.96
    3 "A B B India Ltd."      17167 564  -.02442409  .9734801551860071 15345.77
    3 "A B B India Ltd."      17198 565 .0006490189  .9728723476125267 15355.73
    3 "A B B India Ltd."      17226 566 -.019927137  .9396168938512286 15049.73
    3 "A B B India Ltd."      17257 567    .1519713  .9472120474840884 17336.86
    3 "A B B India Ltd."      17287 568    .1233667  .9599181874858322 19475.65
    3 "A B B India Ltd."      17318 569   .19176115  .9538972886219685 23210.32
    3 "A B B India Ltd."      17348 570   .04756688  .9647019885975509 24314.37
    3 "A B B India Ltd."      17379 571  -.02021963  1.023748820401256 23822.74
    3 "A B B India Ltd."      17410 572     .150596 1.0316329634040111 27410.35
    3 "A B B India Ltd."      17440 573    .2177812  1.037518473143562 33379.81
    3 "A B B India Ltd."      17471 574 -.011173184 1.0001829782265959 33006.85
    3 "A B B India Ltd."      17501 575 -.029051105 1.0057413960255452 32047.96
    3 "A B B India Ltd."      17532 576   -.2591662  .9952697221596232 23742.21
    3 "A B B India Ltd."      17563 577  .031952873 1.0753426531536359 24500.85
    3 "A B B India Ltd."      17592 578   .01539526 1.0773899752741936 24878.04
    3 "A B B India Ltd."      17623 579 -.027597956  .9862432031727675 24191.46
    3 "A B B India Ltd."      17653 580  -.10301331  .9467215833168263 21699.42
    3 "A B B India Ltd."      17684 581  -.20751953  .9650938492657422 17196.36
    3 "A B B India Ltd."      17714 582  -.05101664  .9919978566503982 16319.06
    3 "A B B India Ltd."      17745 583   .14076094  .9712649643249686 18616.15
    3 "A B B India Ltd."      17776 584  -.10654525  .9386155416763365 16632.69
    3 "A B B India Ltd."      17806 585   -.3175564  .9432118136991003 11350.87
    3 "A B B India Ltd."      17837 586  -.18248856  .9885692418759537  9279.47
    3 "A B B India Ltd."      17867 587   .03551039 1.0184319251409255  9608.99
    3 "A B B India Ltd."      17898 588   .05811004  .9828476122532387 10167.36
    3 "A B B India Ltd."      17929 589   -.2337432  .9855806780386467  7790.81
    3 "A B B India Ltd."      17957 590    .1625187 1.0038699646088194  9056.96
    3 "A B B India Ltd."      17988 591   .14026673 1.0135641319093294 10327.35
    3 "A B B India Ltd."      18018 592   .33312815 1.0075055663584047 13767.69
    3 "A B B India Ltd."      18049 593    .1960905 1.0146331818136416  16467.4
    3 "A B B India Ltd."      18079 594  -.10050187  1.010268694383803  14812.4
    3 "A B B India Ltd."      18110 595   .08226037  .9883592039039567 16030.87
    3 "A B B India Ltd."      18141 596  .036814276  .9889228991336497 16621.03
    3 "A B B India Ltd."      18171 597 -.021036526   .998786106294578 16271.38
    3 "A B B India Ltd."      18202 598  -.03802826   .994814282280712 15652.61
    3 "A B B India Ltd."      18232 599   .03871929  .9640555666543652 16258.67
    4 "A B C India Ltd."      17136 563  .015457788   2.12531571368011    21.36
    4 "A B C India Ltd."      17167 564  -.05737705  2.106540172549027    20.13
    4 "A B C India Ltd."      17198 565  -.06459627 2.1026474776643314    18.83
    4 "A B C India Ltd."      17226 566   -.1633466   2.13264423218623    15.76
    4 "A B C India Ltd."      17257 567   .04126984 2.2826001317577425    16.41
    4 "A B C India Ltd."      17287 568   .19359756 2.2161258088594167    19.58
    4 "A B C India Ltd."      17318 569  .021711366 2.3289804436944563    20.01
    4 "A B C India Ltd."      17348 570     -.02625 2.3468817749872364    19.48
    4 "A B C India Ltd."      17379 571    -.042362 2.4391863125261577    18.66
    4 "A B C India Ltd."      17410 572   .17962466 2.4379933103240177    23.77
    4 "A B C India Ltd."      17440 573        .025 2.4094645503384355    24.36
    4 "A B C India Ltd."      17471 574    .0864745 2.1843323023291314    26.47
    4 "A B C India Ltd."      17501 575    .4989796  2.201784105856848    39.68
    4 "A B C India Ltd."      17532 576  -.11708646  2.239462491606524    35.03
    4 "A B C India Ltd."      17563 577  -.15805705  1.966281290930492     29.5
    4 "A B C India Ltd."      17592 578   -.3058608 1.9911506307444555    20.47
    4 "A B C India Ltd."      17623 579    .0778364 1.9887081778953244    22.07
    4 "A B C India Ltd."      17653 580    .2399021 1.9498583944372503    27.36
    4 "A B C India Ltd."      17684 581  -.20039487  1.855595292344104    21.88
    4 "A B C India Ltd."      17714 582 -.037037037 1.7782357082267635    21.07
    4 "A B C India Ltd."      17745 583  .026923077 1.7652526074879313    21.64
    4 "A B C India Ltd."      17776 584  -.16354556 1.7464917969148455     18.1
    4 "A B C India Ltd."      17806 585   -.3686567   1.73308280506418    11.43
    4 "A B C India Ltd."      17837 586   .15839243 1.7062580999479549    13.24
    4 "A B C India Ltd."      17867 587    .2489796 1.6819352303559978    16.53
    4 "A B C India Ltd."      17898 588  -.18137255  1.339620359636421    13.53
    4 "A B C India Ltd."      17929 589  -.02994012 1.3959657970527226    13.13
    4 "A B C India Ltd."      17957 590  -.01234568 1.3924411958949219    12.97
    4 "A B C India Ltd."      17988 591        .125  1.360837225337932    14.59
    4 "A B C India Ltd."      18018 592   .39074075  1.337596528441335    20.29
    4 "A B C India Ltd."      18049 593  -.06790946  1.318452598544504    18.91
    4 "A B C India Ltd."      18079 594   .05714286 1.3276898836335498    19.99
    4 "A B C India Ltd."      18110 595   .15945946 1.3240496957688517    23.18
    4 "A B C India Ltd."      18141 596   .07575758 1.3275163932025096    24.93
    4 "A B C India Ltd."      18171 597  -.01516793 1.2214557582880001    24.55
    4 "A B C India Ltd."      18202 598   .04070407 1.2078684868000416    25.55
    4 "A B C India Ltd."      18232 599  -.04862579 1.1923712046544934    24.31
    5 "A C C Ltd."            17136 563   -.0415839  .9711099075288797 20329.98
    5 "A C C Ltd."            17167 564  -.06015384  .9533818755311491 19109.39
    5 "A C C Ltd."            17198 565  -.11781426  .9523902803166918 16859.48
    5 "A C C Ltd."            17226 566  -.18376757  .9802770047439185 13765.13
    5 "A C C Ltd."            17257 567   .14183626  .9824767111906931 15717.92
    5 "A C C Ltd."            17287 568  .019967813  .9952344940871638 16032.26
    5 "A C C Ltd."            17318 569   .09139785 1.0224756100645327 17498.05
    5 "A C C Ltd."            17348 570   .13509317 1.0278634459236917 19863.05
    5 "A C C Ltd."            17379 571  .005613472 1.0073959448450303 19978.03
    5 "A C C Ltd."            17410 572    .1210245 1.0042391040607614 22409.05
    5 "A C C Ltd."            17440 573   -.0982509 1.0121883760540995 20208.85
    5 "A C C Ltd."            17471 574  .011090487  .8241913020640157 20434.25
    5 "A C C Ltd."            17501 575  -.05961724  .8150590284559912 19222.12
    5 "A C C Ltd."            17532 576  -.23606637   .804711217381253 14684.86
    5 "A C C Ltd."            17563 577   .01284099  .8364281862130032 14873.79
    5 "A C C Ltd."            17592 578   .04213448  .8366475578684974 15500.53
    5 "A C C Ltd."            17623 579   -.0816487  .7422599123501417 14235.28
    5 "A C C Ltd."            17653 580  -.12917683  .6882965015245578  12396.6
    5 "A C C Ltd."            17684 581  -.20911224  .7062767619309206  9804.72
    5 "A C C Ltd."            17714 582   .11827751  .7427678610804371 10964.48
    5 "A C C Ltd."            17745 583  -.03876434  .7420291439720214 10539.54
    5 "A C C Ltd."            17776 584   .08902341  .7477072268416667  11477.8
    5 "A C C Ltd."            17806 585   -.1933295  .6882701570835166  9258.83
    5 "A C C Ltd."            17837 586  -.17663154  .6972659898494115  7623.52
    5 "A C C Ltd."            17867 587   .17636923  .7179109719736483  8969.31
    5 "A C C Ltd."            17898 588   .05639255  .7560042136590477  9475.17
    5 "A C C Ltd."            17929 589  .069228485  .7655877723743578 10131.12
    5 "A C C Ltd."            17957 590   .06826603  .7588711787418411 10822.84
    5 "A C C Ltd."            17988 591   .13240267  .7555921716690642 12255.82
    5 "A C C Ltd."            18018 592   .19908117  .7594557251580196 14696.14
    5 "A C C Ltd."            18049 593 -.018007662   .735764126647085 14431.87
    5 "A C C Ltd."            18079 594   .14618286  .7387278539919047 16542.13
    5 "A C C Ltd."            18110 595   -.0823783  .7502929416085707 15179.54
    5 "A C C Ltd."            18141 596  .013107456  .7589422988668725 15378.51
    5 "A C C Ltd."            18171 597   -.0874527  .7647615071289715  14034.1
    5 "A C C Ltd."            18202 598   .06547181  .7702599729533258 14953.59
    5 "A C C Ltd."            18232 599    .0940246  .7643412933830858 16361.57
    end
    format %td date
    format %tm mdate
    Last edited by Sartaj Hussain; 20 Jan 2023, 13:09.

    Comment


    • #47
      Well, here is a part of what you want. The four variants are really all the same except for the time periods to be split into deciles, and the corresponding dates for the lagged mcap to be used as a weight and the lagged beta to be used for deciles. So this code does it all. To use it, you have to set the "parameters" of your run in the two bold-faced commands. The parameter variant, which must be 1, 2, 3, or 4, is which variant, as you defined them in #44, you wish to use. The second parameter nq is the number of groups to sort into. You have asked for deciles, so I imagine you will typically, or always, set this to 10. (In developing the code, I did not have enough stock id's to do deciles, so I developed it with terciles, hence you see it as nq = 3 here. It dawned on me that someday you will decide you want to use more or fewer quantiles than 10, so why not just leave it as a user-specifiable parameter instead of "hardwiring" 10 into the code.)

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float stock_id str54 stock int date float(mdate rt) double(beta mcap)
      1 "3M India Ltd."         17136 563  .001986755  .9363791897476034  1704.41
      1 "3M India Ltd."         17167 564   .12273628  .9223737930509442   1913.6
      1 "3M India Ltd."         17198 565  .022899864   .922756816668508  1957.42
      1 "3M India Ltd."         17226 566  -.09570672  .8936533493659552  1770.08
      1 "3M India Ltd."         17257 567   .08442055  .9255302588321866  1919.51
      1 "3M India Ltd."         17287 568   .12479826  .9350681183690134  2159.06
      1 "3M India Ltd."         17318 569   .09339456  .9271015207020946  2360.71
      1 "3M India Ltd."         17348 570  -.13650028   .928254346339326  2038.47
      1 "3M India Ltd."         17379 571  -.04351911  .9836310240772113  1949.76
      1 "3M India Ltd."         17410 572   .04327479  .9891430041241998  2034.13
      1 "3M India Ltd."         17440 573    .2355596  .9751046493064751  2513.29
      1 "3M India Ltd."         17471 574   -.1149907  .9956336356126323  2224.29
      1 "3M India Ltd."         17501 575   .16502912 1.0016201663302253  2591.36
      1 "3M India Ltd."         17532 576   -.1716478 1.0163532769060692  2146.56
      1 "3M India Ltd."         17563 577  .018472841  .9914501373606369  2186.21
      1 "3M India Ltd."         17592 578  -.06211676  .9814122102459226  2050.41
      1 "3M India Ltd."         17623 579  .023679366  .9226485941803548  2098.96
      1 "3M India Ltd."         17653 580 -.006896552  .9157756854647555  2084.49
      1 "3M India Ltd."         17684 581  -.09614138  .9080926389855237  1884.08
      1 "3M India Ltd."         17714 582  -.04035874  .8762961854634894  1808.04
      1 "3M India Ltd."         17745 583  .012305296  .8605383835206916  1830.29
      1 "3M India Ltd."         17776 584  -.11377135  .8680215325174288  1622.06
      1 "3M India Ltd."         17806 585   -.3538787  .8790495453705364  1048.05
      1 "3M India Ltd."         17837 586  -.01537056  .9539156687231287  1031.94
      1 "3M India Ltd."         17867 587  .010861852   .933792486219891  1043.15
      1 "3M India Ltd."         17898 588  .021058315  .9699855719761739  1065.11
      1 "3M India Ltd."         17929 589  -.05462718  .9422987555783494  1006.93
      1 "3M India Ltd."         17957 590 -.016613526  .9449352765119065    990.2
      1 "3M India Ltd."         17988 591    .1656428   .923992991288802  1154.22
      1 "3M India Ltd."         18018 592   .21149717  .9315873561349993  1398.33
      1 "3M India Ltd."         18049 593  .035205025  .8966264545990463  1447.56
      1 "3M India Ltd."         18079 594   .12953307  .8952355982767113  1635.07
      1 "3M India Ltd."         18110 595   .07578629  .9026652138700382  1758.98
      1 "3M India Ltd."         18141 596    .1142848  .9015792779073551  1960.01
      1 "3M India Ltd."         18171 597 -.031409852  .8997408733078569  1898.45
      1 "3M India Ltd."         18202 598   .06058448  .8956781585590297  2013.46
      1 "3M India Ltd."         18232 599  .036534533  .8934226024323634  2087.02
      2 "3P Land Holdings Ltd." 17136 563   .27454546  .6063615825199706    12.62
      2 "3P Land Holdings Ltd." 17167 564  -.13552068  .5882292970802359    10.91
      2 "3P Land Holdings Ltd." 17198 565  -.06105611  .5856696529156193    10.24
      2 "3P Land Holdings Ltd." 17226 566   .13884006  .5735485544392244    11.66
      2 "3P Land Holdings Ltd." 17257 567   .12654321  .5503792292363405    13.14
      2 "3P Land Holdings Ltd." 17287 568  .006849315 .48935011341041157    13.23
      2 "3P Land Holdings Ltd." 17318 569  -.05034013  .8768593708147372    12.56
      2 "3P Land Holdings Ltd." 17348 570  .031518623  .8939266963061522    12.96
      2 "3P Land Holdings Ltd." 17379 571   .08194444  .8576006798129209    14.02
      2 "3P Land Holdings Ltd." 17410 572   .07830552  .8595353596032033    15.12
      2 "3P Land Holdings Ltd." 17440 573  -.08809524  .8098852261235144    13.79
      2 "3P Land Holdings Ltd." 17471 574   2.1840732  .6522657484280153     43.9
      2 "3P Land Holdings Ltd." 17501 575    1.496925  .6172125043576382   109.62
      2 "3P Land Holdings Ltd." 17532 576   -.3904762  .7591263309826475    66.82
      2 "3P Land Holdings Ltd." 17563 577   .05414871  .9427380079566117    70.43
      2 "3P Land Holdings Ltd." 17592 578  -.27804753  .9497029550792229    50.85
      2 "3P Land Holdings Ltd." 17623 579   .01238938  .9893970561286551    51.48
      2 "3P Land Holdings Ltd." 17653 580  -.01923077  .9545370561011615    50.49
      2 "3P Land Holdings Ltd." 17684 581    -.315508 1.0104470351402894    34.56
      2 "3P Land Holdings Ltd." 17714 582  .036458332 1.0851988356528055    35.82
      2 "3P Land Holdings Ltd." 17745 583  -.09045226 1.0786019882311453    32.58
      2 "3P Land Holdings Ltd." 17776 584   -.1160221 1.1083191649820048     28.8
      2 "3P Land Holdings Ltd." 17806 585    -.503125  1.114426134944222    14.31
      2 "3P Land Holdings Ltd." 17837 586   .12201258 1.2837179550512692    16.06
      2 "3P Land Holdings Ltd." 17867 587  .036995515  1.225022704005749    16.65
      2 "3P Land Holdings Ltd." 17898 588  -.02702703  1.212781001580348     16.2
      2 "3P Land Holdings Ltd." 17929 589  -.22222222 1.1640822093216887     12.6
      2 "3P Land Holdings Ltd." 17957 590         .25 1.1842704014702627    15.75
      2 "3P Land Holdings Ltd." 17988 591         .08 1.1992254625286194    17.01
      2 "3P Land Holdings Ltd." 18018 592   .24232805  1.159497689882982    21.13
      2 "3P Land Holdings Ltd." 18049 593   .26064736  1.243023955320111    26.64
      2 "3P Land Holdings Ltd." 18079 594  -.02702703 1.2535683448509727    25.92
      2 "3P Land Holdings Ltd." 18110 595 -.007638889  1.231016487071214    25.72
      2 "3P Land Holdings Ltd." 18141 596 .0020993701 1.2431189335636115    25.78
      2 "3P Land Holdings Ltd." 18171 597  -.04539106 1.2032554684323835    24.61
      2 "3P Land Holdings Ltd." 18202 598   -.0380395 1.2059037350629862    23.67
      2 "3P Land Holdings Ltd." 18232 599   .25931558 1.1872302182477175    29.81
      3 "A B B India Ltd."      17136 563    .0601711  .9734345282698555 15729.96
      3 "A B B India Ltd."      17167 564  -.02442409  .9734801551860071 15345.77
      3 "A B B India Ltd."      17198 565 .0006490189  .9728723476125267 15355.73
      3 "A B B India Ltd."      17226 566 -.019927137  .9396168938512286 15049.73
      3 "A B B India Ltd."      17257 567    .1519713  .9472120474840884 17336.86
      3 "A B B India Ltd."      17287 568    .1233667  .9599181874858322 19475.65
      3 "A B B India Ltd."      17318 569   .19176115  .9538972886219685 23210.32
      3 "A B B India Ltd."      17348 570   .04756688  .9647019885975509 24314.37
      3 "A B B India Ltd."      17379 571  -.02021963  1.023748820401256 23822.74
      3 "A B B India Ltd."      17410 572     .150596 1.0316329634040111 27410.35
      3 "A B B India Ltd."      17440 573    .2177812  1.037518473143562 33379.81
      3 "A B B India Ltd."      17471 574 -.011173184 1.0001829782265959 33006.85
      3 "A B B India Ltd."      17501 575 -.029051105 1.0057413960255452 32047.96
      3 "A B B India Ltd."      17532 576   -.2591662  .9952697221596232 23742.21
      3 "A B B India Ltd."      17563 577  .031952873 1.0753426531536359 24500.85
      3 "A B B India Ltd."      17592 578   .01539526 1.0773899752741936 24878.04
      3 "A B B India Ltd."      17623 579 -.027597956  .9862432031727675 24191.46
      3 "A B B India Ltd."      17653 580  -.10301331  .9467215833168263 21699.42
      3 "A B B India Ltd."      17684 581  -.20751953  .9650938492657422 17196.36
      3 "A B B India Ltd."      17714 582  -.05101664  .9919978566503982 16319.06
      3 "A B B India Ltd."      17745 583   .14076094  .9712649643249686 18616.15
      3 "A B B India Ltd."      17776 584  -.10654525  .9386155416763365 16632.69
      3 "A B B India Ltd."      17806 585   -.3175564  .9432118136991003 11350.87
      3 "A B B India Ltd."      17837 586  -.18248856  .9885692418759537  9279.47
      3 "A B B India Ltd."      17867 587   .03551039 1.0184319251409255  9608.99
      3 "A B B India Ltd."      17898 588   .05811004  .9828476122532387 10167.36
      3 "A B B India Ltd."      17929 589   -.2337432  .9855806780386467  7790.81
      3 "A B B India Ltd."      17957 590    .1625187 1.0038699646088194  9056.96
      3 "A B B India Ltd."      17988 591   .14026673 1.0135641319093294 10327.35
      3 "A B B India Ltd."      18018 592   .33312815 1.0075055663584047 13767.69
      3 "A B B India Ltd."      18049 593    .1960905 1.0146331818136416  16467.4
      3 "A B B India Ltd."      18079 594  -.10050187  1.010268694383803  14812.4
      3 "A B B India Ltd."      18110 595   .08226037  .9883592039039567 16030.87
      3 "A B B India Ltd."      18141 596  .036814276  .9889228991336497 16621.03
      3 "A B B India Ltd."      18171 597 -.021036526   .998786106294578 16271.38
      3 "A B B India Ltd."      18202 598  -.03802826   .994814282280712 15652.61
      3 "A B B India Ltd."      18232 599   .03871929  .9640555666543652 16258.67
      4 "A B C India Ltd."      17136 563  .015457788   2.12531571368011    21.36
      4 "A B C India Ltd."      17167 564  -.05737705  2.106540172549027    20.13
      4 "A B C India Ltd."      17198 565  -.06459627 2.1026474776643314    18.83
      4 "A B C India Ltd."      17226 566   -.1633466   2.13264423218623    15.76
      4 "A B C India Ltd."      17257 567   .04126984 2.2826001317577425    16.41
      4 "A B C India Ltd."      17287 568   .19359756 2.2161258088594167    19.58
      4 "A B C India Ltd."      17318 569  .021711366 2.3289804436944563    20.01
      4 "A B C India Ltd."      17348 570     -.02625 2.3468817749872364    19.48
      4 "A B C India Ltd."      17379 571    -.042362 2.4391863125261577    18.66
      4 "A B C India Ltd."      17410 572   .17962466 2.4379933103240177    23.77
      4 "A B C India Ltd."      17440 573        .025 2.4094645503384355    24.36
      4 "A B C India Ltd."      17471 574    .0864745 2.1843323023291314    26.47
      4 "A B C India Ltd."      17501 575    .4989796  2.201784105856848    39.68
      4 "A B C India Ltd."      17532 576  -.11708646  2.239462491606524    35.03
      4 "A B C India Ltd."      17563 577  -.15805705  1.966281290930492     29.5
      4 "A B C India Ltd."      17592 578   -.3058608 1.9911506307444555    20.47
      4 "A B C India Ltd."      17623 579    .0778364 1.9887081778953244    22.07
      4 "A B C India Ltd."      17653 580    .2399021 1.9498583944372503    27.36
      4 "A B C India Ltd."      17684 581  -.20039487  1.855595292344104    21.88
      4 "A B C India Ltd."      17714 582 -.037037037 1.7782357082267635    21.07
      4 "A B C India Ltd."      17745 583  .026923077 1.7652526074879313    21.64
      4 "A B C India Ltd."      17776 584  -.16354556 1.7464917969148455     18.1
      4 "A B C India Ltd."      17806 585   -.3686567   1.73308280506418    11.43
      4 "A B C India Ltd."      17837 586   .15839243 1.7062580999479549    13.24
      4 "A B C India Ltd."      17867 587    .2489796 1.6819352303559978    16.53
      4 "A B C India Ltd."      17898 588  -.18137255  1.339620359636421    13.53
      4 "A B C India Ltd."      17929 589  -.02994012 1.3959657970527226    13.13
      4 "A B C India Ltd."      17957 590  -.01234568 1.3924411958949219    12.97
      4 "A B C India Ltd."      17988 591        .125  1.360837225337932    14.59
      4 "A B C India Ltd."      18018 592   .39074075  1.337596528441335    20.29
      4 "A B C India Ltd."      18049 593  -.06790946  1.318452598544504    18.91
      4 "A B C India Ltd."      18079 594   .05714286 1.3276898836335498    19.99
      4 "A B C India Ltd."      18110 595   .15945946 1.3240496957688517    23.18
      4 "A B C India Ltd."      18141 596   .07575758 1.3275163932025096    24.93
      4 "A B C India Ltd."      18171 597  -.01516793 1.2214557582880001    24.55
      4 "A B C India Ltd."      18202 598   .04070407 1.2078684868000416    25.55
      4 "A B C India Ltd."      18232 599  -.04862579 1.1923712046544934    24.31
      5 "A C C Ltd."            17136 563   -.0415839  .9711099075288797 20329.98
      5 "A C C Ltd."            17167 564  -.06015384  .9533818755311491 19109.39
      5 "A C C Ltd."            17198 565  -.11781426  .9523902803166918 16859.48
      5 "A C C Ltd."            17226 566  -.18376757  .9802770047439185 13765.13
      5 "A C C Ltd."            17257 567   .14183626  .9824767111906931 15717.92
      5 "A C C Ltd."            17287 568  .019967813  .9952344940871638 16032.26
      5 "A C C Ltd."            17318 569   .09139785 1.0224756100645327 17498.05
      5 "A C C Ltd."            17348 570   .13509317 1.0278634459236917 19863.05
      5 "A C C Ltd."            17379 571  .005613472 1.0073959448450303 19978.03
      5 "A C C Ltd."            17410 572    .1210245 1.0042391040607614 22409.05
      5 "A C C Ltd."            17440 573   -.0982509 1.0121883760540995 20208.85
      5 "A C C Ltd."            17471 574  .011090487  .8241913020640157 20434.25
      5 "A C C Ltd."            17501 575  -.05961724  .8150590284559912 19222.12
      5 "A C C Ltd."            17532 576  -.23606637   .804711217381253 14684.86
      5 "A C C Ltd."            17563 577   .01284099  .8364281862130032 14873.79
      5 "A C C Ltd."            17592 578   .04213448  .8366475578684974 15500.53
      5 "A C C Ltd."            17623 579   -.0816487  .7422599123501417 14235.28
      5 "A C C Ltd."            17653 580  -.12917683  .6882965015245578  12396.6
      5 "A C C Ltd."            17684 581  -.20911224  .7062767619309206  9804.72
      5 "A C C Ltd."            17714 582   .11827751  .7427678610804371 10964.48
      5 "A C C Ltd."            17745 583  -.03876434  .7420291439720214 10539.54
      5 "A C C Ltd."            17776 584   .08902341  .7477072268416667  11477.8
      5 "A C C Ltd."            17806 585   -.1933295  .6882701570835166  9258.83
      5 "A C C Ltd."            17837 586  -.17663154  .6972659898494115  7623.52
      5 "A C C Ltd."            17867 587   .17636923  .7179109719736483  8969.31
      5 "A C C Ltd."            17898 588   .05639255  .7560042136590477  9475.17
      5 "A C C Ltd."            17929 589  .069228485  .7655877723743578 10131.12
      5 "A C C Ltd."            17957 590   .06826603  .7588711787418411 10822.84
      5 "A C C Ltd."            17988 591   .13240267  .7555921716690642 12255.82
      5 "A C C Ltd."            18018 592   .19908117  .7594557251580196 14696.14
      5 "A C C Ltd."            18049 593 -.018007662   .735764126647085 14431.87
      5 "A C C Ltd."            18079 594   .14618286  .7387278539919047 16542.13
      5 "A C C Ltd."            18110 595   -.0823783  .7502929416085707 15179.54
      5 "A C C Ltd."            18141 596  .013107456  .7589422988668725 15378.51
      5 "A C C Ltd."            18171 597   -.0874527  .7647615071289715  14034.1
      5 "A C C Ltd."            18202 598   .06547181  .7702599729533258 14953.59
      5 "A C C Ltd."            18232 599    .0940246  .7643412933830858 16361.57
      end
      format %td date
      format %tm mdate
      
      local variant 2 // SET TO DESIRED VARIANT NUMBER: 1, 2, 3, or 4
      local nq 3  // NUMBER OF QUANTILES TO GROUP DATA INTO (SET TO 10 FOR PRODUCTION)
      
      assert inlist(`variant', 1, 2, 3, 4)
      
      xtset stock_id mdate
      
      if `variant' == 1 {
          gen int ref_month = mofd(dofy(yofd(date))- 1)
      }
      else if `variant' == 2 {
          gen int ref_month = mofd(dofh(hofd(date))- 1)
      }
      else if `variant' == 3 {
          gen int ref_month = mofd(dofq(qofd(date))- 1)
      }
      else /* `variant' == 4 */ {
          gen int ref_month = mofd(dofm(mofd(date))- 1)
      }
      format ref_month %tm
      
      rangestat (max) lagged_beta = beta lagged_mcap = mcap, by(stock_id) ///
          interval(mdate ref_month ref_month)
      by mdate, sort: egen beta_quantile = xtile (lagged_beta), nq(`nq')
      
      capture program drop one_weighted_return
      program define one_weighted_return
          if !missing(beta_quantile) {
              foreach v of varlist beta rt {
                  egen numerator = total(lagged_mcap*`v')
                  egen denominator = total(lagged_mcap)
                  gen vw_mean_`v' = numerator/denominator
                  egen ew_mean_`v' = mean(`v')
                  drop numerator denominator
              }
          }
          keep in 1
          exit
      end
      
      
      
      runby one_weighted_return, by(mdate beta_quantile)
      keep mdate beta_quantile *_mean_rt
      
      drop if missing(beta_quantile, vw_mean_rt, ew_mean_rt) // THIS COMMAND SHOULD PREVENT THE RESHAPE ERROR
      
      gen str32 group = "beta_group" + string(beta_quantile) + "_"
      drop *_quantile
      reshape wide ew_mean_@rt vw_mean_@rt, i(mdate) j(group) string
      What you don't have here is the Newey-adjusted mean rt. I cannot figure out how to do that. You are grouping the data by quantiles (deciles) of the preceding period's beta. Each such group contains multiple different stock_id's. As a result, this group is panel data, not a single time series. Stata's -newey- command accepts only a single time series, not panel data. So there doesn't seem to be any way to apply it to the deciles, only to single stocks. Perhaps I am missing something here or misunderstanding your request?

      Comment


      • #48
        I used the #47 and it worked. I produce output here as example (only three deciles from each equal and value)

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input float(mdate vw_mean_beta_group10_rt ew_mean_beta_group10_rt vw_mean_beta_group1_rt ew_mean_beta_group1_rt vw_mean_beta_group2_rt ew_mean_beta_group2_rt)
        564  -.069573894   .14122373    .011305213    .06751904   .013397406    .05426269
        565   -.18366148  -.15820535    -.08376976   -.07038874   -.05485694   -.07824679
        566   -.04306811  -.07018959   -.006865805   -.03049617  -.001967761   -.04801307
        567    .08066323   .06978887     .03750523    .05594177     .0559518    .04856485
        568   .016455859   .04192624    .003465172    .03972684    .05820238    .04680517
        569    .02976301   .07487746    .008144066    .06093329  -.006526623    .03848907
        570    .08313441   .03802537    .017770346    .02732088    .06022498   .030787153
        571   -.05387822   .05800821   -.020365957    .02609168    .00553042   -.01085015
        572    .14826597   .15642917     .05387788    .08216332     .1491609     .0901516
        573     .1065947   .03785477     .05302673    .00782487    .10664212    .01980347
        574   -.05659011   .10446577    -.04898866    .08624668    .01820308     .0822244
        575    .13082106    .3583659     .14002377    .27490294     .0945476     .2644893
        576   -.26518956  -.28594333    -.15908194   -.21132804   -.12538438    -.2183809
        577  -.022576695   -.0466231   .0018446773  -.034738913    .01717831  -.005884993
        578   -.21755964   -.2080427    -.07682955   -.10343826   -.12415984   -.13666625
        579     .2134448   .20630588     .13711767    .12664269     .0973355    .11137694
        580   -.06698665  -.06868593    .011145898  -.005924954   -.07556514  -.032523446
        581   -.30191785  -.21035466    -.12309827   -.11762534   -.16102608    -.1210906
        582    .19565023   .04825027  -.0023254862    .01224084    .10265373    .05017467
        583   -.05204588 -.009266408     .04538925    .03058959    .02553801   .014173233
        584    -.2985733  -.21147685    -.08949219   -.09478215     -.091689   -.13222922
        585    -.3620828   -.3534486     -.1468863    -.2076658    -.2451624   -.26307017
        586   -.11780066  -.14359318   -.023477394  -.067555815   -.14164913   -.08742792
        587    .29546005   .19973522    .002707344    .05913784     .0827656     .0755463
        588   -.04564368 -.073872924     .03889788   -.04084891   -.02520113   -.04043449
        589   -.07589833  -.05916571   -.020072967  -.017283585   -.07794324  -.035309695
        590    .11970158   .04095529     .04224483    .04834683     .1114108     .0440054
        591    .29435834    .3382188     .08608633    .10148216     .1920039    .15812127
        592     .5250233    .6393412      .0638709    .22348784     .2015679     .3205671
        593   .001325985 -.068133205     .07194705   .006636021    .03922732   .010904074
        594    .06783437   .04609631     .15643603    .07394677    .18422267    .10062657
        595    .06784743    .1582158    -.01681382    .06047933    .06182555    .10083406
        596    .06980382    .0739469    .063544676    .07028879    .07728733    .11633317
        597    -.0881592   -.1110167    .027035056   .012811056   -.04156655   -.02416465
        598    .07273566    .0965229     .05130851    .05908256    .07897895    .09035255
        599    .04627455   .08767387     .02586628     .0773951    .05170223    .11181684
        600   -.05282854 .0009396328   -.033892967  -.008386236   -.04851804 -.0004687917
        601   -.03095399  -.03882915      .0167184   .007368569   .028842693  .0042834003
        602    .03621834   .03867541     .05823719    .04984041   .028647456     .0478367
        603   .071462326   .12398878    .020922985   .067787945   .016201278    .12667292
        604   -.11632793  -.11029593    .015369397  -.005298583   .008477892     -.029979
        605    .04406929  .070680745     .07389385     .0758053     .0276949    .05412912
        606    .00654698  .007583237   -.007041297    .02712537   .014650074    .04287446
        607  .0010683016  .005729464    .006410234    .02281931    .03986061    .04437478
        608    .09655342   .06097738      .0876658    .04343266    .06657151    .07207655
        609  -.025622377   .01513679  .00011145943    .04001379  -.019979756   .030138636
        610   -.11805701  -.11240812    .011627587   -.01095349  -.020607786   -.06184707
        611    .08080666   .02268876     .04627566   .014694327    .08255655   .028567586
        612   -.13842699  -.15050384    -.08320683   -.06116068    -.0751317   -.08068152
        613   -.06725133  -.08433064    -.02130498   -.03305938   -.04942308   -.06486986
        614    .07047717   .04040394     .06142813     .0456071     .0824912    .01999825
        615   -.01218973   .05792754    .013406713    .07737502   .004711271    .07665985
        616   -.04974694  -.06886097    .017082285     .0192753   -.02549763   -.02879855
        617    -.0241563  -.02955193    .029151734  -.000640304  -.021396637  -.002779445
        618   -.08135109  .008711488 -.00028309086    .05189978  -.003840788    .03964788
        619    -.1544876    -.155136    -.05066141    -.0543033   -.09817446   -.09832785
        620   -.05697385 -.019510165  .00007127011   .006270954   .003881647     .0202191
        621    .06374928   .04693407     .06867337    .04547181    .04138917    .01932142
        622   -.15257813  -.14656593    -.04014155   -.05485608   -.09334685   -.09265784
        623    -.1011168  -.10543916  -.0017058988  -.036610257    -.0404849   -.05647845
        624     .3240523   .27771795     .02532167    .08671316    .05046269     .1155114
        625    .06109158   .08361781    .031578925    .04560729     .0583095    .03345582
        626   -.06799864  -.05787953     .04750871   .017639888    .02080993   -.03571866
        627   -.05027087 -.007139353    .009108265    .03901171   -.04403985    .04343025
        628   -.11368205  -.10553768   -.027890746  -.024095396  -.017534604   -.05280221
        629    .05974374   .07308992     .05570702     .0244732    .04150975    .01650549
        630   -.08012232 -.015000622   -.008861238  .0006804575   -.03698075 .00015016733
        631  -.072832696  -.03965755     .03854504    .02002731    .02533807   .010792623
        632     .1653256   .13074672     .02896969    .03736216    .07323179    .05706522
        633  -.026731355   .00409735    .005458168   .015502807   -.04814835   .002638001
        634    .03619187    .0451788    .032085676   .017463773    .05357154    .02642022
        635     .0751393  .015040932    -.00234316    .02279772   .002041388   .009311268
        636   -.01581534  -.04287848     .02023725  -.016824523     .0786187  -.003095927
        637    -.1647812   -.1336552   -.019143935   -.04268749  -.063991785  -.073294446
        638    -.1123465  -.12585041     .02982613  -.011932785   -.02275182   -.05065421
        639    .07568238   .10157068    .036909796    .04349817   .013925192    .04012588
        640   -.01258915  -.04997497     .04557867    .01194489   -.01325538   .030025985
        641   -.07157328  -.08731563    -.02074406  -.019477174   -.02796742   -.04218195
        642    -.0695378  -.11596739     .06472216   -.01944186 -.0010940465   -.02441672
        643    .03124093 -.009565897    -.04223926   -.04299325 -.0045282138   -.04765318
        644    .08652658   .08889922     .05551625    .05980924    .06238613    .04132406
        645    .15808083   .13793524    .017648827   .004821346    .05034951     .0493017
        646     .0772111   .07840928   -.021397445    .03119091   -.01194463    .05300012
        647    .08188674    .1368832    .023907466    .04918174    .02677846    .04496229
        648   -.09485254  -.07161066    .006733114   .012785043    .03203123  -.009124842
        649  -.005156547 -.004271527    .021860605   .007761074    .03968621     .0275657
        650    .13156423   .11171634   -.005731414    .03018948     .0974186     .0553532
        651   .067124456   .11191143   -.010879216    .04109732  -.016633723    .05990125
        652     .2545461   .28876662    .001772805     .0887676    .03351086    .13600926
        653    .13426457    .2016679     .05529561    .12980682    .09944734    .17648974
        654   -.00701943 -.032589182     .06146507    .06596106    .05393412     .0149946
        655    .03566252  .019841567     .08743196    .04405018    .05547304    .04891517
        656   -.07855821   .04384519     .04594529     .0915662    .04230145     .0825342
        657    .09936514   .06278654    -.01943981   .024423316   .014783466   .022805197
        658 -.0006577618 -.001832496     .04711094    .05191277    .05336958    .06162035
        659   -.04643425  -.02176831   -.011570204 -.0009548378   -.03794467  -.009414295
        660    .05531574    .0604055      .0804444    .05656355    .06557648     .0464213
        661   -.02454317 -.016333882     .05712884   .006222455   .006838163  .0037435736
        662   -.05888023 -.070271954   -.024752794   -.03906148 .00030744675   -.04393643
        663   .015231222   .04645855   -.031853292    .05073597   -.06678462   .034384582
        end
        format %tm mdate

        To this master file i need to merge the data with identical dates on three factors stored in file with path:

        F:\capm analysis\three_factors.dta

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input float(mdate mkt smb hml)
        564   .021803737   .04399709  .072298646
        565    -.0991017 -.019725926 -.000827774
        566   .002659279 -.064214155  .002599798
        567    .06511803 -.004996456  .016848855
        568    .04578332 -.009145819 -.011191372
        569    .03390178   .03675858  .000446789
        570    .05944144 -.029051905  .016899977
        571  -.031314977   .03441129  .005402759
        572    .10770207  -.06490261   .05404924
        573    .19564106  -.09692977 -.032733485
        574   .023987835  .024902545   .09831972
        575    .05867732   .17845206    .0937691
        576   -.21697918  -.03870283  -.08182178
        577  -.028289244  -.04034214  -.04070015
        578    -.1596253  -.02819276 -.023015693
        579    .12008452  .018959537   .06865603
        580   -.05787259  .009433594  .007432908
        581   -.19442552  .029585496 -.017319694
        582    .08167857  -.05795717   .04369532
        583 -.0000719003 -.005783826  .001155436
        584   -.12718858 -.063438416   .02035834
        585    -.2773926 -.034869432   .03978702
        586   -.06653973  -.05663194   .07532565
        587     .0901688 -.001884267  .009347156
        588     -.032834 -.036119737 -.032164626
        589  -.032820407  .031403445 -.035724014
        590    .09558018  -.06232757  -.04821395
        591    .14537624   .01911813  .015153348
        592    .28930518  .025454223  .070421904
        593   .001683506  -.03529109  -.02989407
        594    .08083248 -.008897305 -.005554177
        595  -.001332164   .13476999   .01707539
        596    .07384575  -.02198379  .036971144
        597  -.063943215  .017554883  -.06236476
        598    .08238584  .004665203  .010610282
        599    .03529656   .06363067   .04867551
        600   -.04318671   .04936986  -.02046956
        601  -.003158171  -.02284504 -.011644302
        602    .03177518 -.000429325   .01339338
        603  -.002458231   .09658906   .03821263
        604  -.068133175 -.011172697  -.05076417
        605    .05323226   .03393526  .004146196
        606   .005644242  .031354874   .01986552
        607  -.028362824  -.03530572   .05678064
        608    .06849256 -.005093642  -.02092934
        609   .008361499 -.024705026   .06822301
        610   -.03839488  -.01180371 -.025858864
        611    .03937607  .006632332  -.04180221
        612   -.10637768 -.009712823  -.02563453
        613  -.037093982 -.009943247  -.02886152
        614    .08453696  -.05943348   -.0074284
        615   -.00348674   .07051414  .027565483
        616   -.01943655  .014745433 -.032545507
        617   .015971716 -.027295437  .006102431
        618  -.015793769   .06368937  .000810227
        619   -.05434243  -.02775958 -.015986428
        620     .0095064   .02908015 -.008255027
        621   .036252044 -.009366483  -.02179006
        622   -.07893877  .002036288 -.007940106
        623  -.014555086 -.005494244 -.019088976
        624     .1020441  -.03160517   .06440236
        625   .017407924 -.018247422  .017904282
        626   .009622243 -.009295825 -.017271157
        627   .031928144   .05399472  .006140044
        628   -.04337325  .016277004  .000314001
        629    .04960612 -.019866075  .016575832
        630   -.02981535  .006179434 -.013222422
        631    .01543813  .025300436  -.03786676
        632    .05679867 -.003372051  .003108777
        633   -.02610923  .012322052   .03742694
        634    .04059115  .011688767 -.010168407
        635   .011730497 -.015263245 -.013710858
        636  -.003551266  -.02825102  -.04102948
        637   -.07207951  -.02279439  -.00753469
        638   .008698813  -.03141981  -.04381149
        639    .04102334 -.005035065  .009335224
        640      .024391 -.004842995 -.018317465
        641   -.02173945  .008523695  -.03316228
        642   .012792258  .008784737  -.06000709
        643  -.013028658 -.032037266   .11906247
        644   .035708282 -.003448542 -.001925677
        645    .07014629  -.03081769   .01191572
        646  -.035876833   .03827762   .04722738
        647   .029131206  .029440496   .05191265
        648   -.02258812   .04016587 -.067260146
        649    .02337539  .035185497  -.04848253
        650    .05009727 -.073216006   .07447709
        651   -.02047215   .06257552    .0559341
        652     .0568037 -.005452737   .11683814
        653     .0469456   .12678832   .04554099
        654    .01367812   .06178192  -.10974798
        655    .05965604    .0532283  -.06482315
        656    .06280217   .14160505  -.04324669
        657    .04514932  -.03819802   .03687756
        658    .03492325  .016013049 -.000920691
        659   .033727612   .01983876   .00619358
        660    .11956312  .009259675 -.019288965
        661    .06672647  -.02250382   -.0302188
        662   .002894478  .019146595  -.04443426
        663    -.0535466   .06424672    .0266164
        end
        format %tm mdate
        Next for both equal and value, we generate HL which is decile 10 minus decile 1. Following this, there is code that was used in past:


        Code:
        gen time = _n
        tsset time
        foreach v of varlist ew_* {
            newey `v', lag(5)
        }
        foreach v of varlist ew_* {
            newey `v' mkt, lag(5)
        }
        foreach v of varlist ew_* {
            newey `v' mkt smb hml, lag(5)
        }
        But the above code would require change as it doesn't calculate for HL portfolio and should work for both value and equal type deciles and their HL. Further, the output should appear in data editor.
        Last edited by Sartaj Hussain; 20 Jan 2023, 20:12.

        Comment


        • #49

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float(mdate vw_mean_beta_group10_rt ew_mean_beta_group10_rt vw_mean_beta_group1_rt ew_mean_beta_group1_rt vw_mean_beta_group2_rt ew_mean_beta_group2_rt)
          564  -.069573894   .14122373    .011305213    .06751904   .013397406    .05426269
          565   -.18366148  -.15820535    -.08376976   -.07038874   -.05485694   -.07824679
          566   -.04306811  -.07018959   -.006865805   -.03049617  -.001967761   -.04801307
          567    .08066323   .06978887     .03750523    .05594177     .0559518    .04856485
          568   .016455859   .04192624    .003465172    .03972684    .05820238    .04680517
          569    .02976301   .07487746    .008144066    .06093329  -.006526623    .03848907
          570    .08313441   .03802537    .017770346    .02732088    .06022498   .030787153
          571   -.05387822   .05800821   -.020365957    .02609168    .00553042   -.01085015
          572    .14826597   .15642917     .05387788    .08216332     .1491609     .0901516
          573     .1065947   .03785477     .05302673    .00782487    .10664212    .01980347
          574   -.05659011   .10446577    -.04898866    .08624668    .01820308     .0822244
          575    .13082106    .3583659     .14002377    .27490294     .0945476     .2644893
          576   -.26518956  -.28594333    -.15908194   -.21132804   -.12538438    -.2183809
          577  -.022576695   -.0466231   .0018446773  -.034738913    .01717831  -.005884993
          578   -.21755964   -.2080427    -.07682955   -.10343826   -.12415984   -.13666625
          579     .2134448   .20630588     .13711767    .12664269     .0973355    .11137694
          580   -.06698665  -.06868593    .011145898  -.005924954   -.07556514  -.032523446
          581   -.30191785  -.21035466    -.12309827   -.11762534   -.16102608    -.1210906
          582    .19565023   .04825027  -.0023254862    .01224084    .10265373    .05017467
          583   -.05204588 -.009266408     .04538925    .03058959    .02553801   .014173233
          584    -.2985733  -.21147685    -.08949219   -.09478215     -.091689   -.13222922
          585    -.3620828   -.3534486     -.1468863    -.2076658    -.2451624   -.26307017
          586   -.11780066  -.14359318   -.023477394  -.067555815   -.14164913   -.08742792
          587    .29546005   .19973522    .002707344    .05913784     .0827656     .0755463
          588   -.04564368 -.073872924     .03889788   -.04084891   -.02520113   -.04043449
          589   -.07589833  -.05916571   -.020072967  -.017283585   -.07794324  -.035309695
          590    .11970158   .04095529     .04224483    .04834683     .1114108     .0440054
          591    .29435834    .3382188     .08608633    .10148216     .1920039    .15812127
          592     .5250233    .6393412      .0638709    .22348784     .2015679     .3205671
          593   .001325985 -.068133205     .07194705   .006636021    .03922732   .010904074
          594    .06783437   .04609631     .15643603    .07394677    .18422267    .10062657
          595    .06784743    .1582158    -.01681382    .06047933    .06182555    .10083406
          596    .06980382    .0739469    .063544676    .07028879    .07728733    .11633317
          597    -.0881592   -.1110167    .027035056   .012811056   -.04156655   -.02416465
          598    .07273566    .0965229     .05130851    .05908256    .07897895    .09035255
          599    .04627455   .08767387     .02586628     .0773951    .05170223    .11181684
          600   -.05282854 .0009396328   -.033892967  -.008386236   -.04851804 -.0004687917
          601   -.03095399  -.03882915      .0167184   .007368569   .028842693  .0042834003
          602    .03621834   .03867541     .05823719    .04984041   .028647456     .0478367
          603   .071462326   .12398878    .020922985   .067787945   .016201278    .12667292
          604   -.11632793  -.11029593    .015369397  -.005298583   .008477892     -.029979
          605    .04406929  .070680745     .07389385     .0758053     .0276949    .05412912
          606    .00654698  .007583237   -.007041297    .02712537   .014650074    .04287446
          607  .0010683016  .005729464    .006410234    .02281931    .03986061    .04437478
          608    .09655342   .06097738      .0876658    .04343266    .06657151    .07207655
          609  -.025622377   .01513679  .00011145943    .04001379  -.019979756   .030138636
          610   -.11805701  -.11240812    .011627587   -.01095349  -.020607786   -.06184707
          611    .08080666   .02268876     .04627566   .014694327    .08255655   .028567586
          612   -.13842699  -.15050384    -.08320683   -.06116068    -.0751317   -.08068152
          613   -.06725133  -.08433064    -.02130498   -.03305938   -.04942308   -.06486986
          614    .07047717   .04040394     .06142813     .0456071     .0824912    .01999825
          615   -.01218973   .05792754    .013406713    .07737502   .004711271    .07665985
          616   -.04974694  -.06886097    .017082285     .0192753   -.02549763   -.02879855
          617    -.0241563  -.02955193    .029151734  -.000640304  -.021396637  -.002779445
          618   -.08135109  .008711488 -.00028309086    .05189978  -.003840788    .03964788
          619    -.1544876    -.155136    -.05066141    -.0543033   -.09817446   -.09832785
          620   -.05697385 -.019510165  .00007127011   .006270954   .003881647     .0202191
          621    .06374928   .04693407     .06867337    .04547181    .04138917    .01932142
          622   -.15257813  -.14656593    -.04014155   -.05485608   -.09334685   -.09265784
          623    -.1011168  -.10543916  -.0017058988  -.036610257    -.0404849   -.05647845
          624     .3240523   .27771795     .02532167    .08671316    .05046269     .1155114
          625    .06109158   .08361781    .031578925    .04560729     .0583095    .03345582
          626   -.06799864  -.05787953     .04750871   .017639888    .02080993   -.03571866
          627   -.05027087 -.007139353    .009108265    .03901171   -.04403985    .04343025
          628   -.11368205  -.10553768   -.027890746  -.024095396  -.017534604   -.05280221
          629    .05974374   .07308992     .05570702     .0244732    .04150975    .01650549
          630   -.08012232 -.015000622   -.008861238  .0006804575   -.03698075 .00015016733
          631  -.072832696  -.03965755     .03854504    .02002731    .02533807   .010792623
          632     .1653256   .13074672     .02896969    .03736216    .07323179    .05706522
          633  -.026731355   .00409735    .005458168   .015502807   -.04814835   .002638001
          634    .03619187    .0451788    .032085676   .017463773    .05357154    .02642022
          635     .0751393  .015040932    -.00234316    .02279772   .002041388   .009311268
          636   -.01581534  -.04287848     .02023725  -.016824523     .0786187  -.003095927
          637    -.1647812   -.1336552   -.019143935   -.04268749  -.063991785  -.073294446
          638    -.1123465  -.12585041     .02982613  -.011932785   -.02275182   -.05065421
          639    .07568238   .10157068    .036909796    .04349817   .013925192    .04012588
          640   -.01258915  -.04997497     .04557867    .01194489   -.01325538   .030025985
          641   -.07157328  -.08731563    -.02074406  -.019477174   -.02796742   -.04218195
          642    -.0695378  -.11596739     .06472216   -.01944186 -.0010940465   -.02441672
          643    .03124093 -.009565897    -.04223926   -.04299325 -.0045282138   -.04765318
          644    .08652658   .08889922     .05551625    .05980924    .06238613    .04132406
          645    .15808083   .13793524    .017648827   .004821346    .05034951     .0493017
          646     .0772111   .07840928   -.021397445    .03119091   -.01194463    .05300012
          647    .08188674    .1368832    .023907466    .04918174    .02677846    .04496229
          648   -.09485254  -.07161066    .006733114   .012785043    .03203123  -.009124842
          649  -.005156547 -.004271527    .021860605   .007761074    .03968621     .0275657
          650    .13156423   .11171634   -.005731414    .03018948     .0974186     .0553532
          651   .067124456   .11191143   -.010879216    .04109732  -.016633723    .05990125
          652     .2545461   .28876662    .001772805     .0887676    .03351086    .13600926
          653    .13426457    .2016679     .05529561    .12980682    .09944734    .17648974
          654   -.00701943 -.032589182     .06146507    .06596106    .05393412     .0149946
          655    .03566252  .019841567     .08743196    .04405018    .05547304    .04891517
          656   -.07855821   .04384519     .04594529     .0915662    .04230145     .0825342
          657    .09936514   .06278654    -.01943981   .024423316   .014783466   .022805197
          658 -.0006577618 -.001832496     .04711094    .05191277    .05336958    .06162035
          659   -.04643425  -.02176831   -.011570204 -.0009548378   -.03794467  -.009414295
          660    .05531574    .0604055      .0804444    .05656355    .06557648     .0464213
          661   -.02454317 -.016333882     .05712884   .006222455   .006838163  .0037435736
          662   -.05888023 -.070271954   -.024752794   -.03906148 .00030744675   -.04393643
          663   .015231222   .04645855   -.031853292    .05073597   -.06678462   .034384582
          end
          format %tm mdate
          tempfile output47
          save `output47'
          
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float(mdate mkt smb hml)
          564   .021803737   .04399709  .072298646
          565    -.0991017 -.019725926 -.000827774
          566   .002659279 -.064214155  .002599798
          567    .06511803 -.004996456  .016848855
          568    .04578332 -.009145819 -.011191372
          569    .03390178   .03675858  .000446789
          570    .05944144 -.029051905  .016899977
          571  -.031314977   .03441129  .005402759
          572    .10770207  -.06490261   .05404924
          573    .19564106  -.09692977 -.032733485
          574   .023987835  .024902545   .09831972
          575    .05867732   .17845206    .0937691
          576   -.21697918  -.03870283  -.08182178
          577  -.028289244  -.04034214  -.04070015
          578    -.1596253  -.02819276 -.023015693
          579    .12008452  .018959537   .06865603
          580   -.05787259  .009433594  .007432908
          581   -.19442552  .029585496 -.017319694
          582    .08167857  -.05795717   .04369532
          583 -.0000719003 -.005783826  .001155436
          584   -.12718858 -.063438416   .02035834
          585    -.2773926 -.034869432   .03978702
          586   -.06653973  -.05663194   .07532565
          587     .0901688 -.001884267  .009347156
          588     -.032834 -.036119737 -.032164626
          589  -.032820407  .031403445 -.035724014
          590    .09558018  -.06232757  -.04821395
          591    .14537624   .01911813  .015153348
          592    .28930518  .025454223  .070421904
          593   .001683506  -.03529109  -.02989407
          594    .08083248 -.008897305 -.005554177
          595  -.001332164   .13476999   .01707539
          596    .07384575  -.02198379  .036971144
          597  -.063943215  .017554883  -.06236476
          598    .08238584  .004665203  .010610282
          599    .03529656   .06363067   .04867551
          600   -.04318671   .04936986  -.02046956
          601  -.003158171  -.02284504 -.011644302
          602    .03177518 -.000429325   .01339338
          603  -.002458231   .09658906   .03821263
          604  -.068133175 -.011172697  -.05076417
          605    .05323226   .03393526  .004146196
          606   .005644242  .031354874   .01986552
          607  -.028362824  -.03530572   .05678064
          608    .06849256 -.005093642  -.02092934
          609   .008361499 -.024705026   .06822301
          610   -.03839488  -.01180371 -.025858864
          611    .03937607  .006632332  -.04180221
          612   -.10637768 -.009712823  -.02563453
          613  -.037093982 -.009943247  -.02886152
          614    .08453696  -.05943348   -.0074284
          615   -.00348674   .07051414  .027565483
          616   -.01943655  .014745433 -.032545507
          617   .015971716 -.027295437  .006102431
          618  -.015793769   .06368937  .000810227
          619   -.05434243  -.02775958 -.015986428
          620     .0095064   .02908015 -.008255027
          621   .036252044 -.009366483  -.02179006
          622   -.07893877  .002036288 -.007940106
          623  -.014555086 -.005494244 -.019088976
          624     .1020441  -.03160517   .06440236
          625   .017407924 -.018247422  .017904282
          626   .009622243 -.009295825 -.017271157
          627   .031928144   .05399472  .006140044
          628   -.04337325  .016277004  .000314001
          629    .04960612 -.019866075  .016575832
          630   -.02981535  .006179434 -.013222422
          631    .01543813  .025300436  -.03786676
          632    .05679867 -.003372051  .003108777
          633   -.02610923  .012322052   .03742694
          634    .04059115  .011688767 -.010168407
          635   .011730497 -.015263245 -.013710858
          636  -.003551266  -.02825102  -.04102948
          637   -.07207951  -.02279439  -.00753469
          638   .008698813  -.03141981  -.04381149
          639    .04102334 -.005035065  .009335224
          640      .024391 -.004842995 -.018317465
          641   -.02173945  .008523695  -.03316228
          642   .012792258  .008784737  -.06000709
          643  -.013028658 -.032037266   .11906247
          644   .035708282 -.003448542 -.001925677
          645    .07014629  -.03081769   .01191572
          646  -.035876833   .03827762   .04722738
          647   .029131206  .029440496   .05191265
          648   -.02258812   .04016587 -.067260146
          649    .02337539  .035185497  -.04848253
          650    .05009727 -.073216006   .07447709
          651   -.02047215   .06257552    .0559341
          652     .0568037 -.005452737   .11683814
          653     .0469456   .12678832   .04554099
          654    .01367812   .06178192  -.10974798
          655    .05965604    .0532283  -.06482315
          656    .06280217   .14160505  -.04324669
          657    .04514932  -.03819802   .03687756
          658    .03492325  .016013049 -.000920691
          659   .033727612   .01983876   .00619358
          660    .11956312  .009259675 -.019288965
          661    .06672647  -.02250382   -.0302188
          662   .002894478  .019146595  -.04443426
          663    -.0535466   .06424672    .0266164
          end
          format %tm mdate
          tempfile 3factors
          save `3factors'
          
          clear frames
          use `output47', clear
          merge 1:1 mdate using `3factors'
          
          foreach x in vw ew {
              gen HL_`x' = `x'_mean_beta_group10_rt - `x'_mean_beta_group1_rt
          }
          
          gen time = _n
          tsset time
          
          frame create results str32 variable float(b_cons se_cons b_mkt se_mkt ///
              b_smb se_smb b_hml se_hml)
          foreach v of varlist *_mean_beta_group*_rt HL_* {
              newey `v', lag(5)
              frame post results ("`v'") (_b[_cons]) (_se[_cons]) (.) (.) (.) (.) (.) (.)
              newey `v' mkt, lag(5)
              frame post results ("`v'") (_b[_cons]) (_se[_cons]) (_b[mkt]) (_se[mkt]) ////
                  (.) (.) (.) (.)
              newey `v' mkt smb hml, lag(5)
              frame post results ("`v'") (_b[_cons]) (_se[_cons]) (_b[mkt]) (_se[mkt]) ////
                  (_b[smb]) (_se[smb]) (_b[hml]) (_se[hml])
          }
          
          frame change results
          foreach x in cons mkt smb hml {
              gen t_`x' = b_`x'/se_`x', after(se_`x')
          }
          browse

          Comment


          • #50
            Can you put this code in order. It is not working. I tried this one before running #49.

            Code:
            use "F:\capm analysis\all_risk_measures.dta
            tempfile output47
            save `output47'
            use "F:\capm analysis\three_factors.dta"
            tempfile 3factors
             save `3factors'
            But it has produced following error.

            use `output47', clear
            invalid file specification
            r(198);
            Last edited by Sartaj Hussain; 20 Jan 2023, 23:25.

            Comment


            • #51
              There is nothing wrong with that code. I suspect the problem is that you ran the 6 lines of code in the code block separately, and then tried to run -use `output47', clear-. That doesn't work because the tempfiles are discarded when the code is interrupted like that. You have to run the entire thing beginning to end with no breaks or interruptions. It is a completely general, inviolable rule in Stata that code containing any local macro must be run without interrupt from the point where the local macro is defined all the way through the final place where the local macro is used.

              But, in any case, there is no need for those first 6 lines of code you show. When I develop the code, I do not save your example data as file on my hard drive. I just use the -datatex- to input the data and then run the code. But when, as here, there is more than one file involved, I do save them as tempfiles, and then -use- the tempfiles in the appropriate places.

              But that is not how you should use it. Where I have -use `output47'- you should replace that with -use "F:\capm analysis\all_risk_measures.dta"-. Where I have -merge 1:1 mdate using `3factors'- you should have -use "F:\capm analysis\three_factors.dta"-. I'm sorry I didn't make that clear when I posted the code--I'll be more attentive to that going forward. I imagined that it would be apparent from reading the code that passing the data from the real files into those tempfiles was not needed for production purposes.
              Last edited by Clyde Schechter; 21 Jan 2023, 11:26.

              Comment


              • #52
                Thanks. It worked well. But just two more changes. Please add generation of adj R_squared for each regression in #49. And average value of sort variable, i.e. average beta for each decile in #47

                Comment


                • #53
                  There is a bit of confusion in the request. The sort variable is not beta, it is the "lagged_beta," the beta that prevailed in the month preceding the start of the year/half-year/quarter/month. I assume that what you want is the mean of the lagged beta, not the mean of the betas in the current months.

                  Code:
                  * Example generated by -dataex-. For more info, type help dataex
                  clear
                  input float stock_id str54 stock int date float(mdate rt) double(beta mcap)
                  1 "3M India Ltd."         17136 563  .001986755  .9363791897476034  1704.41
                  1 "3M India Ltd."         17167 564   .12273628  .9223737930509442   1913.6
                  1 "3M India Ltd."         17198 565  .022899864   .922756816668508  1957.42
                  1 "3M India Ltd."         17226 566  -.09570672  .8936533493659552  1770.08
                  1 "3M India Ltd."         17257 567   .08442055  .9255302588321866  1919.51
                  1 "3M India Ltd."         17287 568   .12479826  .9350681183690134  2159.06
                  1 "3M India Ltd."         17318 569   .09339456  .9271015207020946  2360.71
                  1 "3M India Ltd."         17348 570  -.13650028   .928254346339326  2038.47
                  1 "3M India Ltd."         17379 571  -.04351911  .9836310240772113  1949.76
                  1 "3M India Ltd."         17410 572   .04327479  .9891430041241998  2034.13
                  1 "3M India Ltd."         17440 573    .2355596  .9751046493064751  2513.29
                  1 "3M India Ltd."         17471 574   -.1149907  .9956336356126323  2224.29
                  1 "3M India Ltd."         17501 575   .16502912 1.0016201663302253  2591.36
                  1 "3M India Ltd."         17532 576   -.1716478 1.0163532769060692  2146.56
                  1 "3M India Ltd."         17563 577  .018472841  .9914501373606369  2186.21
                  1 "3M India Ltd."         17592 578  -.06211676  .9814122102459226  2050.41
                  1 "3M India Ltd."         17623 579  .023679366  .9226485941803548  2098.96
                  1 "3M India Ltd."         17653 580 -.006896552  .9157756854647555  2084.49
                  1 "3M India Ltd."         17684 581  -.09614138  .9080926389855237  1884.08
                  1 "3M India Ltd."         17714 582  -.04035874  .8762961854634894  1808.04
                  1 "3M India Ltd."         17745 583  .012305296  .8605383835206916  1830.29
                  1 "3M India Ltd."         17776 584  -.11377135  .8680215325174288  1622.06
                  1 "3M India Ltd."         17806 585   -.3538787  .8790495453705364  1048.05
                  1 "3M India Ltd."         17837 586  -.01537056  .9539156687231287  1031.94
                  1 "3M India Ltd."         17867 587  .010861852   .933792486219891  1043.15
                  1 "3M India Ltd."         17898 588  .021058315  .9699855719761739  1065.11
                  1 "3M India Ltd."         17929 589  -.05462718  .9422987555783494  1006.93
                  1 "3M India Ltd."         17957 590 -.016613526  .9449352765119065    990.2
                  1 "3M India Ltd."         17988 591    .1656428   .923992991288802  1154.22
                  1 "3M India Ltd."         18018 592   .21149717  .9315873561349993  1398.33
                  1 "3M India Ltd."         18049 593  .035205025  .8966264545990463  1447.56
                  1 "3M India Ltd."         18079 594   .12953307  .8952355982767113  1635.07
                  1 "3M India Ltd."         18110 595   .07578629  .9026652138700382  1758.98
                  1 "3M India Ltd."         18141 596    .1142848  .9015792779073551  1960.01
                  1 "3M India Ltd."         18171 597 -.031409852  .8997408733078569  1898.45
                  1 "3M India Ltd."         18202 598   .06058448  .8956781585590297  2013.46
                  1 "3M India Ltd."         18232 599  .036534533  .8934226024323634  2087.02
                  2 "3P Land Holdings Ltd." 17136 563   .27454546  .6063615825199706    12.62
                  2 "3P Land Holdings Ltd." 17167 564  -.13552068  .5882292970802359    10.91
                  2 "3P Land Holdings Ltd." 17198 565  -.06105611  .5856696529156193    10.24
                  2 "3P Land Holdings Ltd." 17226 566   .13884006  .5735485544392244    11.66
                  2 "3P Land Holdings Ltd." 17257 567   .12654321  .5503792292363405    13.14
                  2 "3P Land Holdings Ltd." 17287 568  .006849315 .48935011341041157    13.23
                  2 "3P Land Holdings Ltd." 17318 569  -.05034013  .8768593708147372    12.56
                  2 "3P Land Holdings Ltd." 17348 570  .031518623  .8939266963061522    12.96
                  2 "3P Land Holdings Ltd." 17379 571   .08194444  .8576006798129209    14.02
                  2 "3P Land Holdings Ltd." 17410 572   .07830552  .8595353596032033    15.12
                  2 "3P Land Holdings Ltd." 17440 573  -.08809524  .8098852261235144    13.79
                  2 "3P Land Holdings Ltd." 17471 574   2.1840732  .6522657484280153     43.9
                  2 "3P Land Holdings Ltd." 17501 575    1.496925  .6172125043576382   109.62
                  2 "3P Land Holdings Ltd." 17532 576   -.3904762  .7591263309826475    66.82
                  2 "3P Land Holdings Ltd." 17563 577   .05414871  .9427380079566117    70.43
                  2 "3P Land Holdings Ltd." 17592 578  -.27804753  .9497029550792229    50.85
                  2 "3P Land Holdings Ltd." 17623 579   .01238938  .9893970561286551    51.48
                  2 "3P Land Holdings Ltd." 17653 580  -.01923077  .9545370561011615    50.49
                  2 "3P Land Holdings Ltd." 17684 581    -.315508 1.0104470351402894    34.56
                  2 "3P Land Holdings Ltd." 17714 582  .036458332 1.0851988356528055    35.82
                  2 "3P Land Holdings Ltd." 17745 583  -.09045226 1.0786019882311453    32.58
                  2 "3P Land Holdings Ltd." 17776 584   -.1160221 1.1083191649820048     28.8
                  2 "3P Land Holdings Ltd." 17806 585    -.503125  1.114426134944222    14.31
                  2 "3P Land Holdings Ltd." 17837 586   .12201258 1.2837179550512692    16.06
                  2 "3P Land Holdings Ltd." 17867 587  .036995515  1.225022704005749    16.65
                  2 "3P Land Holdings Ltd." 17898 588  -.02702703  1.212781001580348     16.2
                  2 "3P Land Holdings Ltd." 17929 589  -.22222222 1.1640822093216887     12.6
                  2 "3P Land Holdings Ltd." 17957 590         .25 1.1842704014702627    15.75
                  2 "3P Land Holdings Ltd." 17988 591         .08 1.1992254625286194    17.01
                  2 "3P Land Holdings Ltd." 18018 592   .24232805  1.159497689882982    21.13
                  2 "3P Land Holdings Ltd." 18049 593   .26064736  1.243023955320111    26.64
                  2 "3P Land Holdings Ltd." 18079 594  -.02702703 1.2535683448509727    25.92
                  2 "3P Land Holdings Ltd." 18110 595 -.007638889  1.231016487071214    25.72
                  2 "3P Land Holdings Ltd." 18141 596 .0020993701 1.2431189335636115    25.78
                  2 "3P Land Holdings Ltd." 18171 597  -.04539106 1.2032554684323835    24.61
                  2 "3P Land Holdings Ltd." 18202 598   -.0380395 1.2059037350629862    23.67
                  2 "3P Land Holdings Ltd." 18232 599   .25931558 1.1872302182477175    29.81
                  3 "A B B India Ltd."      17136 563    .0601711  .9734345282698555 15729.96
                  3 "A B B India Ltd."      17167 564  -.02442409  .9734801551860071 15345.77
                  3 "A B B India Ltd."      17198 565 .0006490189  .9728723476125267 15355.73
                  3 "A B B India Ltd."      17226 566 -.019927137  .9396168938512286 15049.73
                  3 "A B B India Ltd."      17257 567    .1519713  .9472120474840884 17336.86
                  3 "A B B India Ltd."      17287 568    .1233667  .9599181874858322 19475.65
                  3 "A B B India Ltd."      17318 569   .19176115  .9538972886219685 23210.32
                  3 "A B B India Ltd."      17348 570   .04756688  .9647019885975509 24314.37
                  3 "A B B India Ltd."      17379 571  -.02021963  1.023748820401256 23822.74
                  3 "A B B India Ltd."      17410 572     .150596 1.0316329634040111 27410.35
                  3 "A B B India Ltd."      17440 573    .2177812  1.037518473143562 33379.81
                  3 "A B B India Ltd."      17471 574 -.011173184 1.0001829782265959 33006.85
                  3 "A B B India Ltd."      17501 575 -.029051105 1.0057413960255452 32047.96
                  3 "A B B India Ltd."      17532 576   -.2591662  .9952697221596232 23742.21
                  3 "A B B India Ltd."      17563 577  .031952873 1.0753426531536359 24500.85
                  3 "A B B India Ltd."      17592 578   .01539526 1.0773899752741936 24878.04
                  3 "A B B India Ltd."      17623 579 -.027597956  .9862432031727675 24191.46
                  3 "A B B India Ltd."      17653 580  -.10301331  .9467215833168263 21699.42
                  3 "A B B India Ltd."      17684 581  -.20751953  .9650938492657422 17196.36
                  3 "A B B India Ltd."      17714 582  -.05101664  .9919978566503982 16319.06
                  3 "A B B India Ltd."      17745 583   .14076094  .9712649643249686 18616.15
                  3 "A B B India Ltd."      17776 584  -.10654525  .9386155416763365 16632.69
                  3 "A B B India Ltd."      17806 585   -.3175564  .9432118136991003 11350.87
                  3 "A B B India Ltd."      17837 586  -.18248856  .9885692418759537  9279.47
                  3 "A B B India Ltd."      17867 587   .03551039 1.0184319251409255  9608.99
                  3 "A B B India Ltd."      17898 588   .05811004  .9828476122532387 10167.36
                  3 "A B B India Ltd."      17929 589   -.2337432  .9855806780386467  7790.81
                  3 "A B B India Ltd."      17957 590    .1625187 1.0038699646088194  9056.96
                  3 "A B B India Ltd."      17988 591   .14026673 1.0135641319093294 10327.35
                  3 "A B B India Ltd."      18018 592   .33312815 1.0075055663584047 13767.69
                  3 "A B B India Ltd."      18049 593    .1960905 1.0146331818136416  16467.4
                  3 "A B B India Ltd."      18079 594  -.10050187  1.010268694383803  14812.4
                  3 "A B B India Ltd."      18110 595   .08226037  .9883592039039567 16030.87
                  3 "A B B India Ltd."      18141 596  .036814276  .9889228991336497 16621.03
                  3 "A B B India Ltd."      18171 597 -.021036526   .998786106294578 16271.38
                  3 "A B B India Ltd."      18202 598  -.03802826   .994814282280712 15652.61
                  3 "A B B India Ltd."      18232 599   .03871929  .9640555666543652 16258.67
                  4 "A B C India Ltd."      17136 563  .015457788   2.12531571368011    21.36
                  4 "A B C India Ltd."      17167 564  -.05737705  2.106540172549027    20.13
                  4 "A B C India Ltd."      17198 565  -.06459627 2.1026474776643314    18.83
                  4 "A B C India Ltd."      17226 566   -.1633466   2.13264423218623    15.76
                  4 "A B C India Ltd."      17257 567   .04126984 2.2826001317577425    16.41
                  4 "A B C India Ltd."      17287 568   .19359756 2.2161258088594167    19.58
                  4 "A B C India Ltd."      17318 569  .021711366 2.3289804436944563    20.01
                  4 "A B C India Ltd."      17348 570     -.02625 2.3468817749872364    19.48
                  4 "A B C India Ltd."      17379 571    -.042362 2.4391863125261577    18.66
                  4 "A B C India Ltd."      17410 572   .17962466 2.4379933103240177    23.77
                  4 "A B C India Ltd."      17440 573        .025 2.4094645503384355    24.36
                  4 "A B C India Ltd."      17471 574    .0864745 2.1843323023291314    26.47
                  4 "A B C India Ltd."      17501 575    .4989796  2.201784105856848    39.68
                  4 "A B C India Ltd."      17532 576  -.11708646  2.239462491606524    35.03
                  4 "A B C India Ltd."      17563 577  -.15805705  1.966281290930492     29.5
                  4 "A B C India Ltd."      17592 578   -.3058608 1.9911506307444555    20.47
                  4 "A B C India Ltd."      17623 579    .0778364 1.9887081778953244    22.07
                  4 "A B C India Ltd."      17653 580    .2399021 1.9498583944372503    27.36
                  4 "A B C India Ltd."      17684 581  -.20039487  1.855595292344104    21.88
                  4 "A B C India Ltd."      17714 582 -.037037037 1.7782357082267635    21.07
                  4 "A B C India Ltd."      17745 583  .026923077 1.7652526074879313    21.64
                  4 "A B C India Ltd."      17776 584  -.16354556 1.7464917969148455     18.1
                  4 "A B C India Ltd."      17806 585   -.3686567   1.73308280506418    11.43
                  4 "A B C India Ltd."      17837 586   .15839243 1.7062580999479549    13.24
                  4 "A B C India Ltd."      17867 587    .2489796 1.6819352303559978    16.53
                  4 "A B C India Ltd."      17898 588  -.18137255  1.339620359636421    13.53
                  4 "A B C India Ltd."      17929 589  -.02994012 1.3959657970527226    13.13
                  4 "A B C India Ltd."      17957 590  -.01234568 1.3924411958949219    12.97
                  4 "A B C India Ltd."      17988 591        .125  1.360837225337932    14.59
                  4 "A B C India Ltd."      18018 592   .39074075  1.337596528441335    20.29
                  4 "A B C India Ltd."      18049 593  -.06790946  1.318452598544504    18.91
                  4 "A B C India Ltd."      18079 594   .05714286 1.3276898836335498    19.99
                  4 "A B C India Ltd."      18110 595   .15945946 1.3240496957688517    23.18
                  4 "A B C India Ltd."      18141 596   .07575758 1.3275163932025096    24.93
                  4 "A B C India Ltd."      18171 597  -.01516793 1.2214557582880001    24.55
                  4 "A B C India Ltd."      18202 598   .04070407 1.2078684868000416    25.55
                  4 "A B C India Ltd."      18232 599  -.04862579 1.1923712046544934    24.31
                  5 "A C C Ltd."            17136 563   -.0415839  .9711099075288797 20329.98
                  5 "A C C Ltd."            17167 564  -.06015384  .9533818755311491 19109.39
                  5 "A C C Ltd."            17198 565  -.11781426  .9523902803166918 16859.48
                  5 "A C C Ltd."            17226 566  -.18376757  .9802770047439185 13765.13
                  5 "A C C Ltd."            17257 567   .14183626  .9824767111906931 15717.92
                  5 "A C C Ltd."            17287 568  .019967813  .9952344940871638 16032.26
                  5 "A C C Ltd."            17318 569   .09139785 1.0224756100645327 17498.05
                  5 "A C C Ltd."            17348 570   .13509317 1.0278634459236917 19863.05
                  5 "A C C Ltd."            17379 571  .005613472 1.0073959448450303 19978.03
                  5 "A C C Ltd."            17410 572    .1210245 1.0042391040607614 22409.05
                  5 "A C C Ltd."            17440 573   -.0982509 1.0121883760540995 20208.85
                  5 "A C C Ltd."            17471 574  .011090487  .8241913020640157 20434.25
                  5 "A C C Ltd."            17501 575  -.05961724  .8150590284559912 19222.12
                  5 "A C C Ltd."            17532 576  -.23606637   .804711217381253 14684.86
                  5 "A C C Ltd."            17563 577   .01284099  .8364281862130032 14873.79
                  5 "A C C Ltd."            17592 578   .04213448  .8366475578684974 15500.53
                  5 "A C C Ltd."            17623 579   -.0816487  .7422599123501417 14235.28
                  5 "A C C Ltd."            17653 580  -.12917683  .6882965015245578  12396.6
                  5 "A C C Ltd."            17684 581  -.20911224  .7062767619309206  9804.72
                  5 "A C C Ltd."            17714 582   .11827751  .7427678610804371 10964.48
                  5 "A C C Ltd."            17745 583  -.03876434  .7420291439720214 10539.54
                  5 "A C C Ltd."            17776 584   .08902341  .7477072268416667  11477.8
                  5 "A C C Ltd."            17806 585   -.1933295  .6882701570835166  9258.83
                  5 "A C C Ltd."            17837 586  -.17663154  .6972659898494115  7623.52
                  5 "A C C Ltd."            17867 587   .17636923  .7179109719736483  8969.31
                  5 "A C C Ltd."            17898 588   .05639255  .7560042136590477  9475.17
                  5 "A C C Ltd."            17929 589  .069228485  .7655877723743578 10131.12
                  5 "A C C Ltd."            17957 590   .06826603  .7588711787418411 10822.84
                  5 "A C C Ltd."            17988 591   .13240267  .7555921716690642 12255.82
                  5 "A C C Ltd."            18018 592   .19908117  .7594557251580196 14696.14
                  5 "A C C Ltd."            18049 593 -.018007662   .735764126647085 14431.87
                  5 "A C C Ltd."            18079 594   .14618286  .7387278539919047 16542.13
                  5 "A C C Ltd."            18110 595   -.0823783  .7502929416085707 15179.54
                  5 "A C C Ltd."            18141 596  .013107456  .7589422988668725 15378.51
                  5 "A C C Ltd."            18171 597   -.0874527  .7647615071289715  14034.1
                  5 "A C C Ltd."            18202 598   .06547181  .7702599729533258 14953.59
                  5 "A C C Ltd."            18232 599    .0940246  .7643412933830858 16361.57
                  end
                  format %td date
                  format %tm mdate
                  
                  local variant 2 // SET TO DESIRED VARIANT NUMBER: 1, 2, 3, or 4
                  local nq 3  // NUMBER OF QUANTILES TO GROUP DATA INTO (SET TO 10 FOR PRODUCTION)
                  
                  assert inlist(`variant', 1, 2, 3, 4)
                  
                  xtset stock_id mdate
                  
                  if `variant' == 1 {
                      gen int ref_month = mofd(dofy(yofd(date))- 1)
                  }
                  else if `variant' == 2 {
                      gen int ref_month = mofd(dofh(hofd(date))- 1)
                  }
                  else if `variant' == 3 {
                      gen int ref_month = mofd(dofq(qofd(date))- 1)
                  }
                  else /* `variant' == 4 */ {
                      gen int ref_month = mofd(dofm(mofd(date))- 1)
                  }
                  format ref_month %tm
                  
                  rangestat (max) lagged_beta = beta lagged_mcap = mcap, by(stock_id) ///
                      interval(mdate ref_month ref_month)
                  by mdate, sort: egen beta_quantile = xtile (lagged_beta), nq(`nq')
                  by mdate beta_quantile, sort: egen mean_beta = mean(lagged_beta)
                  
                  capture program drop one_weighted_return
                  program define one_weighted_return
                      if !missing(beta_quantile) {
                          foreach v of varlist beta rt {
                              egen numerator = total(lagged_mcap*`v')
                              egen denominator = total(lagged_mcap)
                              gen vw_mean_`v' = numerator/denominator
                              egen ew_mean_`v' = mean(`v')
                              drop numerator denominator
                          }
                      }
                      keep in 1
                      exit
                  end
                  
                  
                  
                  runby one_weighted_return, by(mdate beta_quantile)
                  keep mdate beta_quantile *_mean_rt mean_beta
                  
                  drop if missing(beta_quantile, vw_mean_rt, ew_mean_rt) // THIS COMMAND SHOULD PREVENT THE RESHAPE ERROR
                  
                  gen str32 group = "beta_group" + string(beta_quantile) + "_"
                  drop *_quantile
                  reshape wide ew_mean_@rt vw_mean_@rt mean_@beta, i(mdate) j(group) string

                  Comment


                  • #54
                    As for adjusted R2 in the code in #49, the -newey- command does not return any such statistic. And, although there are many "pretenders," in general there is no statistic that is truly analogous to R2 for other regression models. The R2 from OLS regressions is liked because it is simultaneously several different things. In other regression models, however, there is usually no statistic that has all of the properties of R2, and the various pseudo-R2 statistics in use typically satisfy some, but not all of those properties. On the assumption that what you are interested in here is some measure of the proportion of variance that the regression model explains, what I have done in the code below is provided you with the square of the correlation between the predicted values of the Newey regression and the observed values. I have not adjusted it for sample size or number of predictors, as I do not know if it even makes sense to do that in the context of a Newey-West regression. (I know next to nothing about Newey-West regression--the kind of data to which it applies simply doesn't arise in my area.) Even if it does make sense, given that it took 21 hours to run some of the code on your original data set, I am quite confident that your sample sizes will be large enough that the adjustment that would be made would be negligible. To make it clear that this is not a bona fide R2 statistic, I am calling it corr_sq.

                    Finally, I should point out that in the case of the first regression, which has only the constant term as a predictor, R2 is necessarily 0.

                    Code:
                    clear frames
                    use output_of_code_in_#47_dataset, clear
                    merge 1:1 mdate using 3_factors_dataset
                    
                    foreach x in vw ew {
                        gen HL_`x' = `x'_mean_beta_group10_rt - `x'_mean_beta_group1_rt
                    }
                    
                    gen time = _n
                    tsset time
                    
                    frame create results str32 variable float(b_cons se_cons b_mkt se_mkt ///
                        b_smb se_smb b_hml se_hml corr_sq)
                    foreach v of varlist *_mean_beta_group*_rt HL_* {
                        newey `v', lag(5)
                        frame post results ("`v'") (_b[_cons]) (_se[_cons]) (.) (.) (.) (.) (.) (.) ///
                            (0)
                        newey `v' mkt, lag(5)
                        predict xb if e(sample)
                        corr xb `v'
                        frame post results ("`v'") (_b[_cons]) (_se[_cons]) (_b[mkt]) (_se[mkt]) ////
                            (.) (.) (.) (.) (r(rho)^2)
                        drop xb
                        newey `v' mkt smb hml, lag(5)
                        predict xb if e(sample)
                        corr xb `v'
                        frame post results ("`v'") (_b[_cons]) (_se[_cons]) (_b[mkt]) (_se[mkt]) ////
                            (_b[smb]) (_se[smb]) (_b[hml]) (_se[hml]) (r(rho)^2)
                        drop xb
                    }
                    
                    frame change results
                    foreach x in cons mkt smb hml {
                        gen t_`x' = b_`x'/se_`x', after(se_`x')
                    }
                    browse

                    Comment


                    • #55
                      Kindly refer to #12 of this thread. We used it on monthly data. Now, I want to use it on a dataset with daily data of rt. What change is to be brought to #12.

                      Comment


                      • #56
                        I see several issues and need further information:

                        1. The calculations require classifying stock_ids based on percentiles of mcap from the previous June and bmr from the previous March. As you now have daily data, there will be 30 different values of mcap for each June and 31 for each March. So do you want to use the value from the first of the month, or the last, or the 15th, or some kind of median or mean value?

                        2. The calculations also require weighted averages weighted by the previous June's mcap. Will you use the same choice of mcap from among those of the previous June as used for the median mcap split grouping? Or something different.

                        3. In calculating the weighted mean returns, the code in #12 did so in every mcap-bmr-group separately every month. Do you now want a separate weighted mean in every mcap-bmr-group every day? If not, how do you want to aggregate up to larger time units?

                        4. The final results from the code in #12 are monthly observations of mean returns in each mcap-bmr-group (along with SMB and HML). Do you now want daily observations as the result? If not, how do you want to aggregate up to larger time units?

                        Comment


                        • #57
                          My reply is below:

                          1. The value from last of the month or end of the month.
                          2. Same previous June's mcap for weighted averages as used for median mcap split grouping.
                          3. Yes, i want a separate weighted mean in every mcap-bmr-group every day.
                          4. The final results should also be in daily observation form.

                          Comment


                          • #58
                            I'm interpreting "last of the month or end of the month" to mean the last date within the month for which a value of mcap or bmr is available. I don't know how those variables are ascertained, but I can imagine that if the actual last calendar day of the month falls on a weekend or holiday, there might be no value available, so in that case we go back to the last date on which mcap or bmr is actually assessed.

                            I believe the following code will do the job. Note that the variable mdate is no longer used, everything now is done in terms of the daily variable date.

                            Code:
                            gen moy = month(date)
                            gen year = year(date)
                            
                            //  CREATE A "FISCAL YEAR" RUNNING FROM JULY THROUGH SUBSEQUENT JUNE
                            gen fyear = cond(moy > 6, year, year-1)
                            frame put stock_id fyear moy year date mcap bmr ///
                                if (!missing(mcap) | !missing(bmr)) & inlist(moy, 3, 6), into(mcap_bmr_work)
                            frame change mcap_bmr_work
                            by stock_id year moy (date), sort: keep if _n == _N // KEEP LAST DAY OF MONTH
                            isid stock_id fyear moy, sort
                            replace fyear = year
                            collapse (first) bmr (last) mcap, by(stock_id fyear)
                            
                            frame change default
                            rename (mcap bmr) orig=
                            frlink m:1 stock_id fyear, frame(mcap_bmr_work)
                            frget mcap bmr, from(mcap_bmr_work)
                            label var mcap "mcap June Preceding FY"
                            label var bmr "bmr March Preceding FY"
                            frame drop mcap_bmr_work
                            drop mcap_bmr_work
                            egen byte representative = tag(stock_id fyear)
                            
                            //  MEDIAN SPLIT BASED ON JUNE VALUE OF mcap
                            capture program drop one_year_median_split
                            program define one_year_median_split
                                xtile june_mcap_group = mcap, nq(2)
                                exit
                            end
                            frame put stock_id fyear mcap if representative & !missing(mcap), into(median_split)
                            frame change median_split
                            runby one_year_median_split, by(fyear)
                            frame change default
                            frlink m:1 stock_id fyear, frame(median_split stock_id fyear) // ***
                            frget june_mcap_group, from(median_split)
                            frame drop median_split
                            drop median_split
                            
                            //  SPLIT AT 30TH AND 70TH PERCENTILES OF bmr
                            capture program drop one_year_three_groups
                            program define one_year_three_groups
                                if _N > = 3 {
                                    _pctile bmr, percentiles(30 70)
                                    gen cut = `r(r1)' in 1
                                    replace cut = `r(r2)' in 2
                                    xtile mar_bmr_group = bmr, cutpoints(cut)
                                }
                                else {
                                    gen mar_bmr_group = .
                                }
                                exit
                            end
                            frame put stock_id fyear bmr if representative & !missing(bmr), into(three_groups) // ***
                            frame change three_groups
                            runby one_year_three_groups, by(fyear) verbose
                            frame change default
                            frlink m:1 stock_id fyear, frame(three_groups stock_id fyear) // ***
                            frget mar_bmr_group, from(three_groups)
                            frame drop three_groups
                            drop three_groups
                            
                            capture program drop one_weighted_return
                            program define one_weighted_return
                                if !missing(june_mcap_group, mar_bmr_group) {
                                    egen numerator = total(mcap*rt)
                                    egen denominator = total(mcap)
                                    gen vw_mean_rt = numerator/denominator
                                }
                                exit
                            end
                            drop if missing(june_mcap_group, mar_bmr_group)
                            runby one_weighted_return, by(date june_mcap_group mar_bmr_group)
                            
                            collapse (first) vw_mean_rt, by(date june_mcap_group mar_bmr_group)
                            drop if missing(vw_mean_rt)
                            keep date june_mcap_group mar_bmr_group vw_mean_rt
                            
                            by date: egen S = mean(cond(june_mcap_group == 1, vw_mean_rt, .))
                            by date: egen B = mean(cond(june_mcap_group == 2, vw_mean_rt, .))
                            gen SMB = S - B
                            
                            by date: egen H = mean(cond(mar_bmr_group == 3, vw_mean_rt, .))
                            by date: egen L = mean(cond(mar_bmr_group == 1, vw_mean_rt, .))
                            gen HML = H - L
                            
                            //  AND IF YOU WANT TO REDUCE TO ONE OBSERVATION PER MONTH
                            label define june_mcap_group 1 "S" 2 "B"
                            label define mar_bmr_group 1 "L" 2 "M" 3 "H"
                            label values june_mcap_group june_mcap_group
                            label values mar_bmr_group mar_bmr_group
                            decode june_mcap_group, gen (mcap_group)
                            decode mar_bmr_group, gen(bmr_group)
                            drop june_mcap_group mar_bmr_group
                            egen groups = concat(mcap_group bmr_group)
                            keep date groups SMB HML vw_mean_rt
                            rename vw_mean_rt =_
                            reshape wide vw_mean_rt_, i(date) j(groups) string

                            Comment


                            • #59
                              This is the output generated by one of codes listed above:

                              Code:
                              * Example generated by -dataex-. For more info, type help dataex
                              clear
                              input float stock_id str52 stock int date float mdate double(pr mcap) float idiovol
                              1 "20 Microns Ltd."  20423 671     36.5    128.8  .15180425
                              1 "20 Microns Ltd."  20454 672     27.3    96.33  .10950197
                              1 "20 Microns Ltd."  20485 673     26.1     92.1  .09301163
                              1 "20 Microns Ltd."  20514 674    28.15    99.33  .07924972
                              1 "20 Microns Ltd."  20545 675     31.7   111.86    .158713
                              1 "20 Microns Ltd."  20575 676    28.55   100.74 .072114795
                              1 "20 Microns Ltd."  20606 677     29.7    104.8  .06689945
                              1 "20 Microns Ltd."  20636 678     29.3   103.39  .06400682
                              1 "20 Microns Ltd."  20667 679     38.2   134.79  .21093673
                              1 "20 Microns Ltd."  20698 680    36.45   128.62   .0909415
                              1 "20 Microns Ltd."  20728 681    40.65   143.44  .08971238
                              1 "20 Microns Ltd."  20759 682     35.7   125.97  .10669856
                              1 "20 Microns Ltd."  20789 683    32.95   116.27  .08298702
                              1 "20 Microns Ltd."  20820 684    38.75   136.74  .14690407
                              1 "20 Microns Ltd."  20851 685    36.05   127.21  .05534502
                              1 "20 Microns Ltd."  20879 686       35    123.5  .06207231
                              1 "20 Microns Ltd."  20910 687     43.9   154.91  .22075494
                              1 "20 Microns Ltd."  20940 688    37.25   131.44  .07736997
                              1 "20 Microns Ltd."  20971 689    37.85   133.56  .08051722
                              1 "20 Microns Ltd."  21001 690    38.55   136.03   .0807961
                              1 "20 Microns Ltd."  21032 691    37.45   132.15 .069374084
                              1 "20 Microns Ltd."  21063 692     41.7   147.14  .13633128
                              1 "20 Microns Ltd."  21093 693     51.4   181.37   .1800664
                              1 "20 Microns Ltd."  21124 694     58.3   205.72  .14240031
                              1 "20 Microns Ltd."  21154 695     58.3   205.72   .1068619
                              1 "20 Microns Ltd."  21185 696    52.75   186.14   .1121357
                              1 "20 Microns Ltd."  21216 697     50.5    178.2   .0620272
                              1 "20 Microns Ltd."  21244 698     49.1   173.26   .1247453
                              1 "20 Microns Ltd."  21275 699     47.6   167.96  .14557002
                              1 "20 Microns Ltd."  21305 700       43   151.73  .14636737
                              1 "20 Microns Ltd."  21336 701     35.6   125.62  .07735473
                              1 "20 Microns Ltd."  21366 702     41.7   147.14   .0823111
                              1 "20 Microns Ltd."  21397 703    49.25   173.79  .16660585
                              1 "20 Microns Ltd."  21428 704    42.45   149.79   .0817884
                              1 "20 Microns Ltd."  21458 705     42.8   151.03  .05799506
                              1 "20 Microns Ltd."  21489 706     42.8   151.03  .10888863
                              1 "20 Microns Ltd."  21519 707     42.2   148.91  .04020227
                              1 "20 Microns Ltd."  21550 708    37.05   130.74  .07178653
                              1 "20 Microns Ltd."  21581 709    36.55   128.97  .10064302
                              1 "20 Microns Ltd."  21609 710     38.2   134.79   .0774306
                              1 "20 Microns Ltd."  21640 711     37.1   130.91  .04773393
                              1 "20 Microns Ltd."  21670 712     40.6   143.26  .10399453
                              1 "20 Microns Ltd."  21701 713    37.05   130.74   .0635552
                              1 "20 Microns Ltd."  21731 714     33.8   119.27  .07565823
                              1 "20 Microns Ltd."  21762 715    33.75   119.09  .10563102
                              1 "20 Microns Ltd."  21793 716    40.05   141.32  .07741617
                              1 "20 Microns Ltd."  21823 717    38.35   135.32  .07788575
                              1 "20 Microns Ltd."  21854 718    33.55   118.39  .08756137
                              1 "20 Microns Ltd."  21884 719     35.2   124.21  .06998083
                              1 "20 Microns Ltd."  21915 720     34.9   123.15  .11265282
                              1 "20 Microns Ltd."  21946 721     31.2   110.09   .0808599
                              1 "20 Microns Ltd."  21975 722    25.55    90.16   .1146018
                              1 "20 Microns Ltd."  22006 723    29.05   102.51  .22777008
                              1 "20 Microns Ltd."  22036 724    26.15    92.27  .05658275
                              1 "20 Microns Ltd."  22067 725     32.4   114.33  .19901267
                              1 "20 Microns Ltd."  22097 726     28.6   100.92  .08823687
                              1 "20 Microns Ltd."  22128 727    30.95   109.21  .11920004
                              1 "20 Microns Ltd."  22159 728    28.25    99.68  .08832553
                              1 "20 Microns Ltd."  22189 729     28.4   100.21  .05650701
                              1 "20 Microns Ltd."  22220 730     32.1   113.27  .07832587
                              1 "20 Microns Ltd."  22250 731     40.2   141.85   .1509842
                              1 "20 Microns Ltd."  22281 732    36.65   129.33  .07885768
                              1 "20 Microns Ltd."  22312 733    36.45   128.62  .06627448
                              1 "20 Microns Ltd."  22340 734    35.15   124.03  .06961816
                              1 "20 Microns Ltd."  22371 735     38.2   134.79  .06409864
                              1 "20 Microns Ltd."  22401 736     64.1   226.19   .3120904
                              1 "20 Microns Ltd."  22432 737    60.15   212.25  .12140137
                              1 "20 Microns Ltd."  22462 738     66.5   234.66   .0796833
                              1 "20 Microns Ltd."  22493 739    53.85   190.02  .07174803
                              1 "20 Microns Ltd."  22524 740     61.2   215.95  .20695087
                              1 "20 Microns Ltd."  22554 741    58.55    206.6  .09502423
                              1 "20 Microns Ltd."  22585 742     58.1   205.01  .07524765
                              1 "20 Microns Ltd."  22615 743    63.45   223.89  .08102456
                              1 "20 Microns Ltd."  22646 744     91.5   322.87    .299464
                              1 "20 Microns Ltd."  22677 745     71.2   251.24   .1011769
                              1 "20 Microns Ltd."  22705 746    73.85   260.59 .069671996
                              1 "20 Microns Ltd."  22736 747       81   285.82  .11349297
                              1 "20 Microns Ltd."  22766 748    80.25   283.17  .16770604
                              1 "20 Microns Ltd."  22797 749     68.6   242.07  .04877379
                              1 "20 Microns Ltd."  22827 750     90.1   317.93   .1762419
                              1 "20 Microns Ltd."  22858 751   109.65   386.92   .2041921
                              1 "20 Microns Ltd."  22889 752    97.75   344.93  .08502114
                              1 "20 Microns Ltd."  22919 753    88.95   313.87 .033111095
                              1 "20 Microns Ltd."  22950 754    93.25   329.05  .08664793
                              1 "20 Microns Ltd."  22980 755    91.05   321.28  .08273523
                              2 "360 One Wam Ltd." 20423 671        .        .          .
                              2 "360 One Wam Ltd." 20454 672        .        .          .
                              2 "360 One Wam Ltd." 20485 673        .        .          .
                              2 "360 One Wam Ltd." 20514 674        .        .          .
                              2 "360 One Wam Ltd." 20545 675        .        .          .
                              2 "360 One Wam Ltd." 20575 676        .        .          .
                              2 "360 One Wam Ltd." 20606 677        .        .          .
                              2 "360 One Wam Ltd." 20636 678        .        .          .
                              2 "360 One Wam Ltd." 20667 679        .        .          .
                              2 "360 One Wam Ltd." 20698 680        .        .          .
                              2 "360 One Wam Ltd." 20728 681        .        .          .
                              2 "360 One Wam Ltd." 20759 682        .        .          .
                              2 "360 One Wam Ltd." 20789 683        .        .          .
                              2 "360 One Wam Ltd." 20820 684        .        .          .
                              2 "360 One Wam Ltd." 20851 685        .        .          .
                              2 "360 One Wam Ltd." 20879 686        .        .          .
                              2 "360 One Wam Ltd." 20910 687        .        .          .
                              2 "360 One Wam Ltd." 20940 688        .        .          .
                              2 "360 One Wam Ltd." 20971 689        .        .          .
                              2 "360 One Wam Ltd." 21001 690        .        .          .
                              2 "360 One Wam Ltd." 21032 691        .        .          .
                              2 "360 One Wam Ltd." 21063 692        .        .          .
                              2 "360 One Wam Ltd." 21093 693        .        .          .
                              2 "360 One Wam Ltd." 21124 694        .        .          .
                              2 "360 One Wam Ltd." 21154 695        .        .          .
                              2 "360 One Wam Ltd." 21185 696        .        .          .
                              2 "360 One Wam Ltd." 21216 697        .        .          .
                              2 "360 One Wam Ltd." 21244 698        .        .          .
                              2 "360 One Wam Ltd." 21275 699        .        .          .
                              2 "360 One Wam Ltd." 21305 700        .        .          .
                              2 "360 One Wam Ltd." 21336 701        .        .          .
                              2 "360 One Wam Ltd." 21366 702        .        .          .
                              2 "360 One Wam Ltd." 21397 703        .        .          .
                              2 "360 One Wam Ltd." 21428 704        .        .          .
                              2 "360 One Wam Ltd." 21458 705        .        .          .
                              2 "360 One Wam Ltd." 21489 706        .        .          .
                              2 "360 One Wam Ltd." 21519 707        .        .          .
                              2 "360 One Wam Ltd." 21550 708        .        .          .
                              2 "360 One Wam Ltd." 21581 709        .        .          .
                              2 "360 One Wam Ltd." 21609 710        .        .          .
                              2 "360 One Wam Ltd." 21640 711        .        .          .
                              2 "360 One Wam Ltd." 21670 712        .        .          .
                              2 "360 One Wam Ltd." 21701 713        .        .          .
                              2 "360 One Wam Ltd." 21731 714        .        .          .
                              2 "360 One Wam Ltd." 21762 715        .        .          .
                              2 "360 One Wam Ltd." 21793 716  1235.05 10724.88          .
                              2 "360 One Wam Ltd." 21823 717  1327.45 11527.26  .10851449
                              2 "360 One Wam Ltd." 21854 718   1311.4 11398.11  .06815534
                              2 "360 One Wam Ltd." 21884 719  1133.85  9876.49  .10201366
                              2 "360 One Wam Ltd." 21915 720  1338.95 11665.33   .1548591
                              2 "360 One Wam Ltd." 21946 721  1463.95  12759.9  .09001794
                              2 "360 One Wam Ltd." 21975 722   1005.8  8768.67  .19371256
                              2 "360 One Wam Ltd." 22006 723   953.05  8308.88    .153316
                              2 "360 One Wam Ltd." 22036 724    844.6  7363.79  .05299322
                              2 "360 One Wam Ltd." 22067 725  1021.75  8910.16  .14037482
                              2 "360 One Wam Ltd." 22097 726  1070.25  9334.51   .0917381
                              2 "360 One Wam Ltd." 22128 727   1023.5  8934.65  .09785583
                              2 "360 One Wam Ltd." 22159 728   961.75  8402.17  .06192819
                              2 "360 One Wam Ltd." 22189 729   919.95  8040.72  .07568683
                              2 "360 One Wam Ltd." 22220 730  1015.65  8896.99  .07538057
                              2 "360 One Wam Ltd." 22250 731  1011.85  8869.69 .072915204
                              2 "360 One Wam Ltd." 22281 732   1013.9  8890.19  .06433145
                              2 "360 One Wam Ltd." 22312 733   1212.4 10650.61    .089387
                              2 "360 One Wam Ltd." 22340 734   1239.4 10892.19  .07450091
                              2 "360 One Wam Ltd." 22371 735  1127.35  9911.39  .08722831
                              2 "360 One Wam Ltd." 22401 736  1185.65 10425.99   .1233501
                              2 "360 One Wam Ltd." 22432 737  1164.35 10239.89  .06242716
                              2 "360 One Wam Ltd." 22462 738   1411.3  12411.7  .14326282
                              2 "360 One Wam Ltd." 22493 739  1621.95 14336.16  .19245663
                              2 "360 One Wam Ltd." 22524 740     1572  13902.7  .08563457
                              2 "360 One Wam Ltd." 22554 741   1629.9 14419.77   .1597674
                              2 "360 One Wam Ltd." 22585 742     1490 13192.93  .07566474
                              2 "360 One Wam Ltd." 22615 743  1419.65 12586.08   .1090008
                              2 "360 One Wam Ltd." 22646 744   1601.2 14197.31  .09659116
                              2 "360 One Wam Ltd." 22677 745  1531.55 13581.43  .07130557
                              2 "360 One Wam Ltd." 22705 746   1668.9 14804.45 .072800726
                              2 "360 One Wam Ltd." 22736 747  1721.15  15271.3  .07746077
                              2 "360 One Wam Ltd." 22766 748   1566.4 13903.23   .1180934
                              2 "360 One Wam Ltd." 22797 749  1481.05  13146.7      .0755
                              2 "360 One Wam Ltd." 22827 750  1671.95 14847.36  .07194163
                              2 "360 One Wam Ltd." 22858 751  1677.45  14898.8  .03754364
                              2 "360 One Wam Ltd." 22889 752   1840.3 16349.15  .12426206
                              2 "360 One Wam Ltd." 22919 753   1771.4 15746.25  .09393045
                              2 "360 One Wam Ltd." 22950 754  1828.55 16259.08 .073346466
                              2 "360 One Wam Ltd." 22980 755   1776.5 15806.88  .04276332
                              3 "3I Infotech Ltd." 20423 671     4.85   308.55   .3060178
                              3 "3I Infotech Ltd." 20454 672     4.65   295.83 .070726916
                              3 "3I Infotech Ltd." 20485 673     3.95   253.12   .1047636
                              3 "3I Infotech Ltd." 20514 674     4.15   265.93  .09094843
                              3 "3I Infotech Ltd." 20545 675     4.25   272.34  .06959453
                              3 "3I Infotech Ltd." 20575 676      3.8   243.51  .07588033
                              3 "3I Infotech Ltd." 20606 677      5.1   326.81   .2280496
                              3 "3I Infotech Ltd." 20636 678      5.1   327.13  .12016416
                              3 "3I Infotech Ltd." 20667 679     5.25   336.76  .19794016
                              3 "3I Infotech Ltd." 20698 680     5.75   516.86  .12810433
                              3 "3I Infotech Ltd." 20728 681     6.65   597.76  .11753883
                              3 "3I Infotech Ltd." 20759 682     5.45   489.89  .13370286
                              3 "3I Infotech Ltd." 20789 683     5.65   591.81  .08836084
                              3 "3I Infotech Ltd." 20820 684      5.6   647.21   .1410187
                              3 "3I Infotech Ltd." 20851 685      5.1   589.43  .06204581
                              3 "3I Infotech Ltd." 20879 686     5.05   597.74  .07652818
                              3 "3I Infotech Ltd." 20910 687      5.5   658.42  .08884872
                              3 "3I Infotech Ltd." 20940 688     4.55   566.92 .065771624
                              3 "3I Infotech Ltd." 20971 689     4.25   546.55  .14354813
                              3 "3I Infotech Ltd." 21001 690     4.15   533.69  .09003264
                              3 "3I Infotech Ltd." 21032 691      4.1   527.26  .08426387
                              3 "3I Infotech Ltd." 21063 692     3.85   513.24   .0749923
                              3 "3I Infotech Ltd." 21093 693      3.8   506.57   .0829519
                              3 "3I Infotech Ltd." 21124 694     3.85   513.24  .10653754
                              3 "3I Infotech Ltd." 21154 695        8  1067.32   .2758485
                              3 "3I Infotech Ltd." 21185 696     6.15   982.81   .1855145
                              3 "3I Infotech Ltd." 21216 697     5.85   943.44   .1086712
                              3 "3I Infotech Ltd." 21244 698     5.05   815.76  .12166346
                              3 "3I Infotech Ltd." 21275 699     4.95   799.68   .1494787
                              3 "3I Infotech Ltd." 21305 700     4.75   767.37   .1535512
                              3 "3I Infotech Ltd." 21336 701     4.25   686.61  .14887816
                              3 "3I Infotech Ltd." 21366 702      3.6    581.6  .12549558
                              3 "3I Infotech Ltd." 21397 703      3.6    581.6  .12537315
                              3 "3I Infotech Ltd." 21428 704      3.4   549.41   .1612394
                              3 "3I Infotech Ltd." 21458 705     3.35   541.33  .18406363
                              3 "3I Infotech Ltd." 21489 706     3.75   605.97  .24836077
                              3 "3I Infotech Ltd." 21519 707      3.6   581.99  .04507526
                              3 "3I Infotech Ltd." 21550 708     3.35   541.58  .10845932
                              3 "3I Infotech Ltd." 21581 709     3.35   541.58   .2566609
                              3 "3I Infotech Ltd." 21609 710     3.85   622.41  .13771889
                              3 "3I Infotech Ltd." 21640 711     3.75   606.24    .203421
                              3 "3I Infotech Ltd." 21670 712      3.5   565.83   .0843905
                              3 "3I Infotech Ltd." 21701 713      3.3   533.49  .09792581
                              3 "3I Infotech Ltd." 21731 714     2.25   363.75  .16281416
                              3 "3I Infotech Ltd." 21762 715     1.75   282.91   .1740527
                              3 "3I Infotech Ltd." 21793 716        2   323.33   .2390153
                              3 "3I Infotech Ltd." 21823 717        2   323.33   .1422637
                              3 "3I Infotech Ltd." 21854 718     1.95   315.25 .074490055
                              3 "3I Infotech Ltd." 21884 719     1.95   315.25  .10634084
                              3 "3I Infotech Ltd." 21915 720     2.25   363.75  .27203667
                              3 "3I Infotech Ltd." 21946 721     1.95   315.25  .17436054
                              3 "3I Infotech Ltd." 21975 722      1.3   210.17   .2019477
                              3 "3I Infotech Ltd." 22006 723      1.6   258.66    .320762
                              3 "3I Infotech Ltd." 22036 724      1.6   258.66  .13443826
                              3 "3I Infotech Ltd." 22067 725      2.7    436.5   .1723641
                              3 "3I Infotech Ltd." 22097 726      2.4      388  .13619053
                              3 "3I Infotech Ltd." 22128 727      3.7   598.16  .13160709
                              3 "3I Infotech Ltd." 22159 728      3.3    533.5   .1590524
                              3 "3I Infotech Ltd." 22189 729        3      485  .10993515
                              3 "3I Infotech Ltd." 22220 730      3.4   549.66  .10065467
                              3 "3I Infotech Ltd." 22250 731     6.45  1042.74  .10150602
                              3 "3I Infotech Ltd." 22281 732     6.65  1075.08  .16562822
                              3 "3I Infotech Ltd." 22312 733     6.15   994.24  .14929815
                              3 "3I Infotech Ltd." 22340 734     7.45  1204.41  .13298213
                              3 "3I Infotech Ltd." 22371 735     7.95  1285.24  .13116848
                              3 "3I Infotech Ltd." 22401 736     8.75  1414.57  .14478727
                              3 "3I Infotech Ltd." 22432 737     9.85  1592.41  .14785117
                              3 "3I Infotech Ltd." 22462 738      9.3  1503.49  .07278715
                              3 "3I Infotech Ltd." 22493 739     8.45  1366.07   .1158908
                              3 "3I Infotech Ltd." 22524 740        .        .          .
                              3 "3I Infotech Ltd." 22554 741    39.45   637.77          .
                              3 "3I Infotech Ltd." 22585 742    97.95  1606.74  .14847663
                              3 "3I Infotech Ltd." 22615 743    94.65  1565.85  .13450299
                              3 "3I Infotech Ltd." 22646 744     77.7   1303.3 .066601284
                              3 "3I Infotech Ltd." 22677 745    51.45   863.69  .08774507
                              3 "3I Infotech Ltd." 22705 746    51.25   860.71  .16721526
                              3 "3I Infotech Ltd." 22736 747    57.75   971.48  .14750819
                              3 "3I Infotech Ltd." 22766 748    46.95   790.56  .09283502
                              3 "3I Infotech Ltd." 22797 749     41.6   700.48  .05987921
                              3 "3I Infotech Ltd." 22827 750    43.05   724.89  .08551042
                              3 "3I Infotech Ltd." 22858 751     44.4   747.65   .1522279
                              3 "3I Infotech Ltd." 22889 752    43.85   738.39  .15209863
                              3 "3I Infotech Ltd." 22919 753     43.9   739.24 .065983735
                              3 "3I Infotech Ltd." 22950 754    42.45   714.82  .05656059
                              3 "3I Infotech Ltd." 22980 755    40.75   686.19  .06333806
                              4 "3M India Ltd."    20423 671 11397.55 12839.42  .07020025
                              4 "3M India Ltd."    20454 672  9881.15 11131.18  .05931601
                              4 "3M India Ltd."    20485 673 10382.15 11695.56  .13843286
                              4 "3M India Ltd."    20514 674 10724.95 12081.73  .04101915
                              4 "3M India Ltd."    20545 675 13323.85 15009.41  .14088234
                              4 "3M India Ltd."    20575 676 12415.15 13985.75  .05856196
                              4 "3M India Ltd."    20606 677 12823.35 14445.59  .03768667
                              4 "3M India Ltd."    20636 678 14619.65 16469.14  .07873284
                              4 "3M India Ltd."    20667 679  12880.8 14510.31  .04725427
                              4 "3M India Ltd."    20698 680  12883.9  14513.8 .028097766
                              4 "3M India Ltd."    20728 681 13296.35 14978.43 .027521065
                              4 "3M India Ltd."    20759 682 11293.45 12722.15  .06654049
                              4 "3M India Ltd."    20789 683  11123.1 12530.25  .04974051
                              4 "3M India Ltd."    20820 684  11957.5 13470.21  .07233124
                              4 "3M India Ltd."    20851 685  11164.8 12577.23  .04566871
                              4 "3M India Ltd."    20879 686 11567.55 13030.93  .03529178
                              4 "3M India Ltd."    20910 687  11499.7 12954.49  .04965758
                              4 "3M India Ltd."    20940 688  13835.2 15585.45  .10944718
                              4 "3M India Ltd."    20971 689  13236.5 14911.01 .031300966
                              4 "3M India Ltd."    21001 690 13378.25 15070.69  .04455712
                              4 "3M India Ltd."    21032 691  14743.8 16608.99  .06961398
                              4 "3M India Ltd."    21063 692  14301.4 16110.63  .02983945
                              4 "3M India Ltd."    21093 693  14190.3 15985.47  .03149755
                              4 "3M India Ltd."    21124 694 15441.15 17394.56  .08963791
                              4 "3M India Ltd."    21154 695 19126.45 21546.08  .12155636
                              4 "3M India Ltd."    21185 696 18796.15 21173.99 .063623324
                              4 "3M India Ltd."    21216 697  20717.4  23338.3  .14194535
                              4 "3M India Ltd."    21244 698 19412.85 21868.71  .03105159
                              4 "3M India Ltd."    21275 699  20524.1 23120.54  .03873885
                              4 "3M India Ltd."    21305 700  19543.6    22016  .04930488
                              4 "3M India Ltd."    21336 701  19637.1 22121.33  .05655072
                              4 "3M India Ltd."    21366 702  23420.9 26383.81  .10948846
                              4 "3M India Ltd."    21397 703    25945 29227.22  .04893228
                              4 "3M India Ltd."    21428 704 22568.05 25423.07 .069898285
                              4 "3M India Ltd."    21458 705 19842.75    22353   .0974772
                              4 "3M India Ltd."    21489 706    21634 24370.85  .05207479
                              4 "3M India Ltd."    21519 707  20824.4 23458.83   .0847318
                              4 "3M India Ltd."    21550 708  20151.6 22700.92  .04413396
                              4 "3M India Ltd."    21581 709 22896.25 25792.79  .09397536
                              4 "3M India Ltd."    21609 710 24260.85 27330.02  .06808542
                              4 "3M India Ltd."    21640 711  22926.7 25827.09  .06719647
                              4 "3M India Ltd."    21670 712  22741.8  25618.8  .06186471
                              4 "3M India Ltd."    21701 713  23215.8 26152.76  .05808556
                              4 "3M India Ltd."    21731 714  21107.9  23778.2  .05762339
                              4 "3M India Ltd."    21762 715 20233.45 22793.12  .03594796
                              end
                              format %td date
                              format %tm mdate
                              From this, by mdate, i need cross-sectional averages of idiovol both simple mean as well as weighted mean (weight = previous month's mcap)

                              Then need to test for trend in the these two averages. Is it possible to develop the vogelsang's trend test that uses following specification:
                              Click image for larger version

Name:	WhatsApp Image 2023-02-03 at 1.06.40 AM.jpeg
Views:	1
Size:	177.5 KB
ID:	1700086
                              :

                              Comment


                              • #60
                                This looks feasible, but an ingredient is missing:
                                and b is a constant tabulated by Vogelsang associated with corresponding significance levels.
                                I need that constant b in order to complete the calculation.

                                Comment

                                Working...
                                X