Below is the example data file:
On this we run the following code:
Then we run regressions on a constant using below code:
It generates output of 25 regressions. What i require from this regression output is a 5 by 5 matrix of intercept values and another 5 by 5 matrix of associated t-values of the intercept. The row of these matrices should reflect idiovol and columns should reflect mcap. What additions to the code need to be put?
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float stock_id str52 stock float(date mdate rt mcap idiovol) 1 "3M India Ltd." . . .04736608 321.22 .0916427 1 "3M India Ltd." . . .04865415 337.95 .11856794 1 "3M India Ltd." . . -.007843738 355.98 .03385014 1 "3M India Ltd." . . -.001308996 354.85 .05559466 1 "3M India Ltd." . . -.012385068 355.98 .022072207 1 "3M India Ltd." . . -.0390713 353.05 . 1 "3M India Ltd." . . -.02738757 340.82 .04476108 1 "3M India Ltd." . . -.067793116 333.05 .0641219 1 "3M India Ltd." . . -.13744837 312.04 .08455227 1 "3M India Ltd." . . .18256493 270.64 .11701576 1 "3M India Ltd." . . .1013674 321.05 .11567125 1 "3M India Ltd." . . .05692589 354.85 .07522642 2 "A B B India Ltd." . . .026357943 1139.01 .09048145 2 "A B B India Ltd." . . .014627993 1174.4 .06662828 2 "A B B India Ltd." . . -.009635856 1197.07 .032479744 2 "A B B India Ltd." . . -.1510767 1191.14 .0478922 2 "A B B India Ltd." . . -.004365709 1016.52 .151155 2 "A B B India Ltd." . . .032454778 1016.31 .08022968 2 "A B B India Ltd." . . .11848308 1053.82 .03937751 2 "A B B India Ltd." . . .14282623 1183.51 .0788861 2 "A B B India Ltd." . . -.10635272 1358.12 .069916405 2 "A B B India Ltd." . . .06663753 1220.17 .08169884 2 "A B B India Ltd." . . .11098332 1305.99 .07204738 2 "A B B India Ltd." . . .069325246 1456.02 .04127121 3 "A C C Ltd." . . -.16770735 2714.39 .0494189 3 "A C C Ltd." . . .032914802 2272.12 .05700322 3 "A C C Ltd." . . -.006490775 2357.53 .0472087 3 "A C C Ltd." . . -.04114424 2353.5 .05463453 3 "A C C Ltd." . . .22832213 2267.27 .05449492 3 "A C C Ltd." . . .005026255 2794.56 .06807207 3 "A C C Ltd." . . -.1387426 2821.04 .04853502 3 "A C C Ltd." . . .07293778 2443.21 .07409048 3 "A C C Ltd." . . -.10571817 2633.1 .08595624 3 "A C C Ltd." . . -.05857307 2367.38 .072985575 3 "A C C Ltd." . . .10611195 2237.47 .05432591 3 "A C C Ltd." . . .14531963 2483.66 .05427632 4 "A D C India Communications Ltd." . . -.15515427 38.98 .0899244 4 "A D C India Communications Ltd." . . .018237507 33.12 .06992178 4 "A D C India Communications Ltd." . . -.09497112 33.88 .09055381 4 "A D C India Communications Ltd." . . -.09403583 30.82 . 4 "A D C India Communications Ltd." . . .08764605 28.06 . 4 "A D C India Communications Ltd." . . .009062549 30.64 .0815558 4 "A D C India Communications Ltd." . . -.157174 31.05 .0749493 4 "A D C India Communications Ltd." . . -.08687963 26.31 .08596274 4 "A D C India Communications Ltd." . . -.09430072 24.15 .12010587 4 "A D C India Communications Ltd." . . .1720329 21.99 .1493983 4 "A D C India Communications Ltd." . . .1829369 25.85 .16625586 4 "A D C India Communications Ltd." . . .10841724 30.68 .1996671 5 "A G C Networks Ltd." . . -.2414415 233.32 .072601065 5 "A G C Networks Ltd." . . .11042874 178.09 .14132822 5 "A G C Networks Ltd." . . -.065180995 198.58 .13915063 5 "A G C Networks Ltd." . . -.1616635 186.56 .1046824 5 "A G C Networks Ltd." . . .1778091 157.21 .08680837 5 "A G C Networks Ltd." . . .12866792 185.81 .11829976 5 "A G C Networks Ltd." . . -.15761645 210.58 .06747569 5 "A G C Networks Ltd." . . -.07685865 178.34 .1158349 5 "A G C Networks Ltd." . . -.18162194 165.46 .0434757 5 "A G C Networks Ltd." . . .0617134 136.21 .06843774 5 "A G C Networks Ltd." . . .19657505 145.11 .161901 5 "A G C Networks Ltd." . . -.005660561 174.21 .1845726 6 "Aarti Industries Ltd." . . -.11743905 80.09 .07460695 6 "Aarti Industries Ltd." . . .06499288 71.05 .13379171 6 "Aarti Industries Ltd." . . -.06215039 76.15 .08399434 6 "Aarti Industries Ltd." . . .06462212 71.72 .08620652 6 "Aarti Industries Ltd." . . -.03837779 76.51 .06567193 6 "Aarti Industries Ltd." . . .019171037 73.84 . 6 "Aarti Industries Ltd." . . .018495552 75.66 .10668948 6 "Aarti Industries Ltd." . . -.07989978 77.42 .10452055 6 "Aarti Industries Ltd." . . -.03729719 71.6 .05122435 6 "Aarti Industries Ltd." . . .06352744 69.17 .14523724 6 "Aarti Industries Ltd." . . .07090741 74.02 . 6 "Aarti Industries Ltd." . . .27436173 79.48 .05161588 7 "Aban Offshore Ltd." . . -.01925893 78.61 .16154055 7 "Aban Offshore Ltd." . . .11436844 77.46 .1599467 7 "Aban Offshore Ltd." . . -.0765941 86.68 .15839635 7 "Aban Offshore Ltd." . . .06841874 80.45 .070136435 7 "Aban Offshore Ltd." . . .13943256 86.31 .0847256 7 "Aban Offshore Ltd." . . .103546 98.71 .11105046 7 "Aban Offshore Ltd." . . .1084034 109.37 .0941147 7 "Aban Offshore Ltd." . . -.08895424 121.73 .09428739 7 "Aban Offshore Ltd." . . -.15765575 111.47 .05114253 7 "Aban Offshore Ltd." . . .0572381 94.43 .07025049 7 "Aban Offshore Ltd." . . .4515534 100.18 .17125925 7 "Aban Offshore Ltd." . . .4910405 145.81 .15821946 8 "Abbott India Ltd." . . -.0927252 483.16 .03758101 8 "Abbott India Ltd." . . .009107584 440.64 .03866321 8 "Abbott India Ltd." . . -.009212272 446.71 . 8 "Abbott India Ltd." . . .0519827 444.69 .04381766 8 "Abbott India Ltd." . . -.014502028 469.8 .04690858 8 "Abbott India Ltd." . . -.029886486 464.94 .04116864 8 "Abbott India Ltd." . . .091593 453.11 .04559331 8 "Abbott India Ltd." . . .02138084 496.69 .07281568 8 "Abbott India Ltd." . . -.14193517 509.65 .04465608 8 "Abbott India Ltd." . . -.05085361 414.78 .04636159 8 "Abbott India Ltd." . . .04385218 395.22 .05140735 8 "Abbott India Ltd." . . .07494023 414.09 .04982206 9 "Accelya Solutions India Ltd." . . -.3571708 77.16 .09019727 9 "Accelya Solutions India Ltd." . . .2496361 49.97 .07974155 9 "Accelya Solutions India Ltd." . . -.13954155 62.67 .12606497 9 "Accelya Solutions India Ltd." . . -.14552286 54.22 .07574052 end format %td date format %tm mdate
Code:
capture program drop one_mdate program define one_mdate gen cutoffs = . _pctile mcap, nq(5) forvalues i = 1/4 { replace cutoffs = r(r`i') in `i' } display `"`cutoffs'"' xtile mcap_quintile = mcap, cutpoints(cutoffs) drop cutoffs by mcap_quintile, sort: egen idiovol_quintile = xtile(idiovol), nq(5) tab *_quintile exit end // DOUBLE SORT EACH FISCAL YEAR runby one_mdate, by(mdate) status capture program drop one_weighted_return program define one_weighted_return if !missing(mcap_quintile,idiovol_quintile){ egen numerator = total(mcap*rt) egen denominator = total(mcap) gen vw_mean_rt = numerator/denominator } exit end runby one_weighted_return, by(mdate mcap_quintile idiovol_quintile) gen int portfolio_num = (mcap_quintile-1)*5 + idiovol_quintile by mdate mcap_quintile idiovol_quintile, sort: egen ew_mean_rt = mean(rt) drop if missing(mcap_quintile,idiovol_quintile, vw_mean_rt, ew_mean_rt) keep mdate *_quintile *_mean_rt by mdate *_quintile, sort: gen stock_count = _N by mdate *_quintile, sort: keep if _n == 1 gen str32 group = "mcap_q" + string(mcap_quintile) +"_idiovol_q" +string(idiovol_q) + "_" drop *_quintile reshape wide @stock_count vw_mean_@rt ew_mean_@rt, i(mdate) j(group) string
Code:
gen time = _n tsset time foreach v of varlist ew_mean_mcap* { newey `v', lag(5) }
Comment