Hey,

Second time writing on this forum.

I am looking to find a way to create an equally weighted stock return for a portfolio of a particular industry to later use a regression returns of two different industry portfolios. Previous example I have seen have create portfolios using percentiles but this would be condition on firm "i" belongs to industrygroup=1 etc. This would later on have to be compared to another portfolio.

Anyone have any tips?


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long permno str8 date str5 ticker float(prc end) double(MktRF SMB HML RF Mom) float(return RetRF IndustryGroup)
87432 "20000131" "A" 66.1875 480  -4.74   4.95  -.29 .41   1.86            .           . 38
87432 "20000229" "A" 103.875 481   2.45   21.7 -9.93 .43  18.36     .5694051   .13940507 38
87432 "20000331" "A"     104 482    5.2 -16.86  7.38 .47  -6.39  .0012033695   -.4687966 38
87432 "20000428" "A"  88.625 483   -6.4  -7.73  8.61 .46  -8.58   -.14783654   -.6078365 38
87432 "20000531" "A"  73.625 484  -4.42  -5.11  2.56  .5  -9.08   -.16925247   -.6692525 38
87432 "20000630" "A"   73.75 485   4.64  13.85 -9.86  .4  16.59   .001697793   -.3983022 38
87432 "20000731" "A"   40.75 486  -2.51  -2.76  8.06 .48   -.11    -.4474576   -.9274576 38
87432 "20000831" "A" 60.3125 487   7.03  -1.15  -.66  .5    5.7    .48006135  -.01993865 38
87432 "20000929" "A" 48.9375 488  -5.45  -1.32  6.13 .51    2.2   -.18860103    -.698601 38
87432 "20001031" "A" 46.3125 489  -2.76   -3.8  5.64 .56  -4.63   -.05363985   -.6136398 38
87432 "20001130" "A" 52.1875 490 -10.72  -2.77 11.26 .51   -2.4     .1268556   -.3831444 38
87432 "20001229" "A"   54.75 491   1.19    .96  7.37  .5    6.7     .0491018   -.4508982 38
87432 "20010131" "A"   54.55 492   3.13   6.54 -4.86 .54 -25.05  -.003652982    -.543653 38
87432 "20010228" "A"      36 493 -10.05   -.72 12.87 .38  12.51     -.340055    -.720055 38
87432 "20010330" "A"   30.73 494  -7.26    .34  6.46 .42   8.35    -.1463889   -.5663889 38
87432 "20010430" "A"   39.01 495   7.94    .54 -4.72 .39  -7.97     .2694435  -.12055649 38
87432 "20010531" "A"   33.54 496    .72   2.59  3.18 .32   2.12   -.14022039   -.4602204 38
87432 "20010629" "A"    32.5 497  -1.94   6.03 -1.03 .28    .34   -.03100778   -.3110078 38
87432 "20010731" "A"   28.61 498  -2.13  -4.35  5.57  .3   5.47   -.11969229   -.4196923 38
87432 "20010831" "A"    26.5 499  -6.46    2.5  2.51 .31   5.54   -.07375046   -.3837505 38
87432 "20010928" "A"   19.55 500  -9.25  -6.12   1.6 .28  11.54    -.2622642  -.54226416 38
87432 "20011031" "A"   22.27 501   2.46   7.63  -8.1 .22  -8.41     .1391305   -.0808695 38
87432 "20011130" "A"   27.27 502   7.54   -.41  2.01 .17  -8.58     .2245173   .05451728 38
87432 "20011231" "A"   28.51 503   1.61   4.57   1.1 .15   -.02    .04547121   -.1045288 38
87432 "20020131" "A"   30.35 504  -1.44   1.19  3.33 .14   3.68    .06453876  -.07546124 38
87432 "20020228" "A"   31.15 505  -2.29   -1.1   2.5 .13   6.76    .02635912  -.10364088 38
87432 "20020328" "A"   34.96 506   4.24   4.23   1.1 .13  -1.66    .12231138 -.007688616 38
87432 "20020430" "A"   30.05 507   -5.2   5.94  3.92 .15   7.95   -.14044623  -.29044622 38
87432 "20020531" "A"   26.37 508  -1.38  -3.21  1.68 .14   2.97    -.1224625   -.2624625 38
87432 "20020628" "A"   23.65 509  -7.21   4.27   .12 .13   6.15   -.10314756  -.23314756 38
87432 "20020731" "A"   18.88 510  -8.18   -5.3 -3.44 .15   3.34   -.20169136   -.3516914 38
87432 "20020830" "A"   13.43 511     .5  -2.44  2.52 .14   1.76    -.2886652   -.4286652 38
87432 "20020930" "A"   13.06 512 -10.35   2.57  1.32 .14   9.09   -.02755025  -.16755025 38
87432 "20021031" "A"   13.75 513   7.84  -2.91 -5.45 .14   -5.3    .05283304  -.08716696 38
87432 "20021129" "A"   19.41 514   5.96   2.84 -1.12 .12 -16.17    .41163635   .29163635 38
87432 "20021231" "A"   17.96 515  -5.76    .01  2.23 .11   9.64    -.0747038   -.1847038 38
87432 "20030131" "A"   16.48 516  -2.57   1.39  -.93  .1   1.61   -.08240532  -.18240532 38
87432 "20030228" "A"    13.2 517  -1.88   -.34 -1.45 .09   1.25    -.1990291  -.28902912 38
87432 "20030331" "A"   13.15 518   1.09    .89 -2.08  .1   1.61  -.003787893   -.1037879 38
87432 "20030430" "A"   16.02 519   8.22    .56  1.03  .1  -9.46      .218251   .11825102 38
87432 "20030530" "A"   18.13 520   6.05   4.69  -.29 .09 -10.77    .13171028   .04171028 38
87432 "20030630" "A"   19.55 521   1.42   1.67   .68  .1  -1.06    .07832323  -.02167677 38
87432 "20030731" "A"   21.73 522   2.35   5.24 -1.13 .07   -.31    .11150897   .04150897 38
87432 "20030829" "A"   24.32 523   2.34    2.6  2.03 .07   -.56    .11919007   .04919007 38
87432 "20030930" "A"   22.11 524  -1.24     .8   .01 .08   -.19   -.09087168  -.17087168 38
87432 "20031031" "A"   24.92 525   6.08   2.68  1.77 .07   3.73    .12709178   .05709178 38
87432 "20031128" "A"   28.28 526   1.35   2.02  1.85 .07   1.62    .13483149   .06483149 38
87432 "20031231" "A"   29.24 527   4.29     -3  2.41 .08  -5.71    .03394622  -.04605378 38
87432 "20040130" "A"   36.86 528   2.15    2.8  1.97 .07    2.6    .26060194   .19060194 38
87432 "20040227" "A"   34.19 529    1.4  -1.43    .5 .06   -1.1  -.072436295  -.13243629 38
87432 "20040331" "A"   31.63 530  -1.32   1.75   .22 .09    .21   -.07487568   -.1648757 38
87432 "20040430" "A"   27.01 531  -1.83  -2.06 -2.62 .08  -5.39   -.14606383  -.22606383 38
87432 "20040528" "A"    25.7 532   1.17   -.21  -.39 .06    1.6   -.04850053  -.10850053 38
87432 "20040630" "A"   29.28 533   1.86   2.26  1.39 .08    2.1     .1392996    .0592996 38
87432 "20040730" "A"   23.81 534  -4.06  -3.81  4.12  .1  -2.29   -.18681698  -.28681698 38
87432 "20040831" "A"    20.5 535    .08  -1.62  1.02 .11  -1.55    -.1390172   -.2490172 38
87432 "20040930" "A"   21.57 536    1.6   3.04  -.25 .11   5.25    .05219511  -.05780489 38
87432 "20041029" "A"   25.06 537   1.43    .31  -.62 .11  -1.52     .1617988   .05179879 38
87432 "20041130" "A"   22.89 538   4.54   3.91   1.8 .15   3.23   -.08659218   -.2365922 38
87432 "20041231" "A"    24.1 539   3.43    .12  -.07 .16  -2.84    .05286156  -.10713844 38
87432 "20050131" "A"   22.11 540  -2.76  -1.51  1.96 .16    3.2    -.0825726   -.2425726 38
87432 "20050228" "A"      24 541   1.89   -.51  1.64 .16   3.16    .08548165  -.07451835 38
87432 "20050331" "A"    22.2 542  -1.97  -1.38  1.59 .21    .54   -.07499997  -.28499997 38
87432 "20050429" "A"   20.75 543  -2.61  -3.98  -.35 .21   -.87   -.06531535  -.27531534 38
87432 "20050531" "A"   24.01 544   3.65   2.88  -.81 .24    .44    .15710844  -.08289156 38
87432 "20050630" "A"   23.02 545    .57   2.62  2.63 .23   2.05   -.04123281   -.2712328 38
87432 "20050729" "A"   26.24 546   3.92   2.93  -.51 .24   -.01    .13987833  -.10012167 38
87432 "20050831" "A"   32.16 547  -1.22   -.92  1.27  .3   2.27    .22560976  -.07439023 38
87432 "20050930" "A"   32.75 548    .49   -.58   .76 .29   3.46   .018345775  -.27165422 38
87432 "20051031" "A"   32.01 549  -2.02  -1.21   .23 .27  -1.29   -.02259547  -.29259548 38
87432 "20051130" "A"   35.66 550   3.61    .91 -1.19 .31    .25    .11402692   -.1959731 38
87432 "20051230" "A"   33.29 551   -.25   -.45   .44 .32    .77   -.06646099    -.386461 38
87432 "20060131" "A"   33.91 552   3.04   5.41  1.12 .35   2.68   .018624179   -.3313758 38
87432 "20060228" "A"      36 553    -.3   -.37  -.25 .34  -1.84    .06163374  -.27836627 38
87432 "20060331" "A"   37.55 554   1.46   3.55    .6 .37   1.26    .04305553   -.3269445 38
87432 "20060428" "A"   38.42 555    .73  -1.34   2.6 .36    .61    .02316908   -.3368309 38
87432 "20060531" "A"   34.89 556  -3.57  -3.04  2.55 .43  -3.65    -.0918792   -.5218792 38
87432 "20060630" "A"   31.56 557   -.35   -.35   .88  .4   1.48   -.09544282   -.4954428 38
87432 "20060731" "A"   28.44 558   -.78  -4.07  2.94  .4  -2.22   -.09885928   -.4988593 38
87432 "20060831" "A"   32.16 559   2.03     .9 -1.71 .42  -3.46    .13080166  -.28919834 38
87432 "20060929" "A"   32.69 560   1.84  -1.37   .05 .41   -.94   .016480062   -.3935199 38
87432 "20061031" "A"    35.6 561   3.23   1.72  -.04 .41   -.23    .08901805  -.32098195 38
87432 "20061130" "A"   31.84 562   1.71    .86   .07 .42  -1.01   -.10561793  -.52561796 38
87432 "20061229" "A"   34.85 563    .87   -1.1  3.15  .4    .84    .09453512   -.3054649 38
87432 "20070131" "A"      32 564    1.4    .11  -.11 .44    .21     -.081779    -.521779 38
87432 "20070228" "A"   31.75 565  -1.96   1.32  -.09 .38  -1.35    -.0078125   -.3878125 38
87432 "20070330" "A"   33.69 566    .68   -.05  -.22 .43   2.49    .06110232   -.3688977 38
87432 "20070430" "A"   34.37 567   3.49  -2.07 -1.15 .44   -.16    .02018404    -.419816 38
87432 "20070531" "A"   38.17 568   3.24    .02  -.04 .41   -.27    .11056152   -.2994385 38
87432 "20070629" "A"   38.44 569  -1.96    .78 -1.12  .4    .37    .00707363   -.3929264 38
87432 "20070731" "A"   38.15 570  -3.73  -2.51 -3.33  .4    2.8   -.00754415   -.4075441 38
87432 "20070831" "A"    36.4 571    .92   -.13 -2.24 .42    .11   -.04587156   -.4658716 38
87432 "20070928" "A"   36.88 572   3.22  -2.29 -1.86 .32   4.59     .0131868   -.3068132 38
87432 "20071031" "A"   36.85 573    1.8    .22  -2.6 .32   4.96 -.0008135193   -.3208135 38
87432 "20071130" "A"   37.83 574  -4.83  -2.62 -1.18 .34    .93   .026594393   -.3134056 38
87432 "20071231" "A"   36.74 575   -.87     .2  -.51 .27   6.52  -.028813114   -.2988131 38
87432 "20080131" "A"   33.86 576  -6.36    -.9  3.65 .21  -7.89    -.0783887   -.2883887 38
87432 "20080229" "A"   30.61 577  -3.09   -.24  -.94 .13   6.11   -.09598346  -.22598346 38
87432 "20080331" "A"   29.83 578   -.93    .95  -.14 .17    4.1   -.02548189   -.1954819 38
87432 "20080430" "A"   30.21 579    4.6  -1.64  -.95 .18    -.2   .012738826  -.16726117 38