Dear Stata Friends, I have 10 portfolios formed every month by sorting stocks based on MAX. After the portfolios are formed, I need to calculate an equal and value weighted average return for each of the10 portfolios and also report the Newey-West t-statistics for each of the equal and value weighted portfolio returns. I actually tried using these stata codes below, however, I doubt I used them correctly:
If I'm not mistaken, I think use of the collapse command
should compute the equal weighted average returns for each of the portfolio, but I am confused on how to generate its t-statistics and the value weighted returns for each of the portfolios as well. Please I need your help on how to get this correctly done, thanks.
Code:
bys period: egen portfo = xtile(max), nq(10) bys period: egen w_ret = wtmean(ret), weight(mv) collapse (mean) ret w_ret, by(period portfo) reshape wide ret w_ret,i(period) j(portfo)
Code:
collapse (mean) ret, by(portfo)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double permno float period double ret float(max mv portfo) 10001 493 -.012658228166401386 .03947368 24414 2 10001 494 .03846153989434242 .04934211 25090 4 10001 495 -.02500000037252903 .032894738 24462.75 2 10001 496 .09743587672710419 .04081629 26846.3 3 10001 497 .11495330929756165 .071428575 29653.4 6 10001 498 .025423744693398476 .13043478 30407.3 9 10001 499 .020661156624555588 .13732716 31035.55 9 10001 500 -.021862395107746124 .03250003 30090.1 3 10001 501 -.03347277268767357 .03076916 29082.9 2 10001 502 -.004329020623117685 .06023421 29256 4 10001 503 .006956504657864571 .0258467 29380.7 2 10001 504 -.013100403361022472 .022093235 28995.8 2 10001 505 -.053097378462553024 .02235129 27488.3 2 10001 506 -.015887869521975517 .04702079 26738.4 5 10001 507 -.043269213289022446 .034313764 25581.45 3 10001 508 .014824124984443188 .02739604 25960.67 2 10001 509 -.024015802890062332 .04205369 25019.28 4 10001 510 -.09979426115751267 .03294372 22522.5 3 10001 511 .01714281365275383 .04891207 22908.6 3 10001 512 -.0016853498527780175 .05555556 22540 5 10001 513 -.01942858099937439 .02857143 22187.88 3 10001 514 -.02389276586472988 .027348455 -21682.875 2 10001 515 -.10614927113056183 .030864196 19046.441 3 10001 516 .14814308285713196 .027227756 21868.04 3 10001 517 .035545047372579575 .08828733 22645.34 8 10001 518 -.1092676967382431 .035792366 19836.45 5 10001 519 -.32418301701545715 .05675676 13405.81 6 10001 520 .6324950456619263 .017218495 21893.36 1 10001 521 -.2879146337509155 .17886177 15595.95 10 10001 522 .01830277033150196 .05405407 15881.4 6 10001 523 .08660134673118591 .06354517 17256.75 7 10001 524 .03759398311376572 .03983364 17905.5 5 10001 525 -.1304347962141037 .066478044 15570 8 10001 526 -.005000034812837839 .04962405 15492.15 6 10001 527 -.0033500806894153357 .025000015 15446.2 3 10001 528 .010084104724228382 .03144753 15601.96 4 10001 529 .07986681163311005 .1008404 16848.04 9 10001 530 .11710327863693237 .030995116 18835.5 4 10001 531 -.01241381373256445 .06213064 18601.68 7 10001 532 -.07960889488458633 .15766422 17120.82 10 10001 533 .010622108355164528 .0431655 17309.34 6 10001 534 .051051076501607895 .06531883 18193 8 10001 535 .004285744391381741 .06015039 18270.97 8 10001 536 -.13229022920131683 .02478135 15853.9 3 10001 537 -.05573765188455582 .03007516 14970.24 4 10001 538 .031249968335032463 .05132743 15438.06 7 10001 539 .16161616146564484 .04347826 17933.1 6 10001 540 -.04057973995804787 .09830507 17178.9 9 10001 541 -.04516613110899925 .05384614 16428.28 8 10001 542 .12482202798128128 .06976749 18663.75 9 10001 543 -.07468356192111969 .1572701 17269.875 10 10001 544 .21903032064437866 .06495473 21052.5 8 10001 545 .1284288913011551 .1785041 26362.65 10 10001 546 .009944767691195011 .18452384 26624.82 10 10001 547 .03938727080821991 .0883978 27673.5 9 10001 548 .21157896518707275 .19047624 33528.63 10 10001 549 -.11903561651706696 .18937197 29421.01 10 10001 550 -.0593966506421566 .0809312 27683 9 10001 551 .021052611991763115 .05022826 28421 7 10001 552 -.01649484969675541 .03578949 27805.7 6 10001 553 -.010537347756326199 .05081084 27522.09 7 10001 554 .17039397358894348 .02423609 32222.68 4 10001 555 -.09463147819042206 .04666664 29173.4 7 10001 556 -.010452263057231903 .1187308 28633.91 10 10001 557 -.07638739794492722 .034410834 26464.68 5 10001 558 .15741683542728424 .04000001 30630.67 5 10001 559 .12357395142316818 .064779095 34122.42 8 10001 560 -.05417025834321976 .05 32417 7 10001 561 .0072727203369140625 .07596154 32652.76 9 10001 562 .051444027572870255 .02775286 33978.91 4 10001 563 -.03729395940899849 .04473686 32844.902 7 10001 564 .023279275745153427 .023239003 33609.508 4 10001 565 .26162126660346985 .03153148 42413.91 5 10001 566 .01973225548863411 .07964598 43438.94 9 10001 567 .002764337230473757 .03431026 43559.02 6 10001 568 .04341829940676689 .04166666 45014.97 7 10001 569 .0006671266746707261 .033731587 42885 6 10001 570 -.05666669085621834 .02096014 40454.85 3 10001 571 .027561862021684647 .01282914 -41569.86 1 10001 572 -.03232463076710701 .04844541 39726.96 4 10001 573 -.04025876894593239 .05958088 38114.25 8 10001 574 .07940071821212769 .05689603 40726.5 7 10001 575 -.003929800353944302 .04194754 40652.5 4 10001 576 -.006082060746848583 .0449123 40250 5 10001 577 .021703556180000305 .05442179 41277.07 5 10001 578 -.05251631140708923 .04437228 38970.855 5 10001 579 -.036698244512081146 .05131413 37384.203 5 10001 580 .271627813577652 .13907287 47382.3 10 10001 581 -.010091708973050117 .18171445 46751.75 10 10001 582 -.05302322283387184 .032045256 44098.86 4 10001 583 -.019723936915397644 .08915143 43055.1 7 10001 584 -.13737370073795319 .06337263 36966.5 7 10001 585 -.01882350631058216 .13333334 36096.7 8 10001 586 -.13012051582336426 .14958455 31225.82 5 10001 587 .1559889167547226 .10929854 35493.223 5 10001 588 .034140389412641525 .0869565 36533.094 4 10001 589 .05622203275561333 .0745756 38415.18 5 10001 590 -.08053683489561081 .09693252 35174 7 10001 591 .04462098702788353 .07122507 36550 3 10001 592 .002941122744232416 .05072465 36921.918 3 end format %tm period
Comment