Dear Clyde,
Require your intervention again. Here is the code that we used to create Fama and French Monthly size(mcap) and value(bmr) factors. Now I want to run this code on daily stock return data. As is defined in this code, groups (portfolios) are to be constructed by making different mcap and bmr sorts only once using, i.e. in june month using june month mcap and march month bmr values. But, instead of monthly weighting the groups to create value-weighted portfolio returns , weighting of portfolios need to be done for each day using begin year june month mcap values. Here is the code and example data set for your perusal.
Require your intervention again. Here is the code that we used to create Fama and French Monthly size(mcap) and value(bmr) factors. Now I want to run this code on daily stock return data. As is defined in this code, groups (portfolios) are to be constructed by making different mcap and bmr sorts only once using, i.e. in june month using june month mcap and march month bmr values. But, instead of monthly weighting the groups to create value-weighted portfolio returns , weighting of portfolios need to be done for each day using begin year june month mcap values. Here is the code and example data set for your perusal.
Code:
gen moy = month(dofm(mdate)) gen year = year(dofm(mdate)) // CREATE A "FISCAL YEAR" RUNNING FROM JULY THROUGH SUBSEQUENT JUNE gen fyear = cond(moy > 6, year, year-1) // 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 year mcap if moy == 6, into(median_split) frame change median_split runby one_year_median_split, by(year) frame change default frlink m:1 stock_id fyear, frame(median_split stock_id year) frget june_mcap_group, from(median_split) frame drop median_split drop median_split // NOW SPLIT AT 30TH AND 70TH PERCENTILES OF bmr capture program drop one_year_three_groups program define one_year_three_groups _pctile bmr, percentiles(30 70) gen cut = `r(r1)' in 1 replace cut = `r(r2)' in 2 xtile march_bmr_group = bmr, cutpoints(cut) exit end frame put stock_id year bmr if moy == 3, into(three_groups) frame change three_groups runby one_year_three_groups, by(year) verbose frame change default frlink m:1 stock_id fyear, frame(three_groups stock_id year) frget march_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, march_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, march_bmr_group) runby one_weighted_return, by(mdate june_mcap_group march_bmr_group) collapse (first) vw_mean_rt, by(mdate june_mcap_group march_bmr_group) drop if missing(vw_mean_rt) keep mdate june_mcap_group march_bmr_group vw_mean_rt isid june_mcap_group march_bmr_group mdate, sort by mdate june_mcap_group, sort: egen temp = mean(vw_mean_rt) by mdate (june_mcap_group), sort: gen SMB = temp[1] - temp[_N] drop temp by mdate march_bmr_group, sort: egen temp = mean(vw_mean_rt) by mdate (march_bmr_group): gen HML = temp[1] - temp[_N] drop temp // AND IF YOU WANT TO REDUCE TO ONE OBSERVATION PER MONTH label define june_mcap_group 1 "S" 2 "B" label define march_bmr_group 1 "L" 2 "M" 3 "H" label values june_mcap_group june_mcap_group label values march_bmr_group march_bmr_group decode june_mcap_group, gen (mcap_group) decode march_bmr_group, gen(bmr_group) drop june_mcap_group march_bmr_group egen groups = concat(mcap_group bmr_group) keep mdate groups SMB HML vw_mean_rt rename vw_mean_rt =_ reshape wide vw_mean_rt_, i(mdate) j(groups) string
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int stock_id str52 stock float(date mdate rt mcap bmr) 1 "3M India Ltd." 15430 506 . . .1984127 1 "3M India Ltd." 15494 509 -.026353067 . . 1 "3M India Ltd." 15495 509 .04813806 . . 1 "3M India Ltd." 15496 509 -.020450585 . . 1 "3M India Ltd." 15497 509 .008138669 . . 1 "3M India Ltd." 15498 509 -.031063553 . . 1 "3M India Ltd." 15501 509 . . . 1 "3M India Ltd." 15502 509 . . . 1 "3M India Ltd." 15503 509 -.010072921 . . 1 "3M India Ltd." 15504 509 -.02210522 . . 1 "3M India Ltd." 15505 509 .015428732 . . 1 "3M India Ltd." 15508 509 .017314466 . . 1 "3M India Ltd." 15509 509 .024487734 . . 1 "3M India Ltd." 15510 509 -.0015257236 . . 1 "3M India Ltd." 15511 509 -.001697793 . . 1 "3M India Ltd." 15512 509 -.034013607 . . 1 "3M India Ltd." 15515 509 .021302775 . . 1 "3M India Ltd." 15516 509 -.0032752345 . . 1 "3M India Ltd." 15517 509 -.02282949 . . 1 "3M India Ltd." 15518 509 .02654867 . . 1 "3M India Ltd." 15519 509 -.016724158 321.22 . 1 "3M India Ltd." 15522 510 .007189263 . . 1 "3M India Ltd." 15523 510 -.007486157 . . 1 "3M India Ltd." 15524 510 .0349062 . . 1 "3M India Ltd." 15525 510 .1 . . 1 "3M India Ltd." 15526 510 -.019106355 . . 1 "3M India Ltd." 15529 510 -.0009424688 . . 1 "3M India Ltd." 15530 510 .017610082 . . 1 "3M India Ltd." 15531 510 -.031520434 . . 1 "3M India Ltd." 15532 510 -.03637522 . . 1 "3M India Ltd." 15533 510 -.000993337 . . 1 "3M India Ltd." 15536 510 -.02220753 . . 1 "3M India Ltd." 15537 510 .016949153 . . 1 "3M India Ltd." 15538 510 -.02666667 . . 1 "3M India Ltd." 15539 510 .013184953 . . 1 "3M India Ltd." 15540 510 .02585768 . . 1 "3M India Ltd." 15543 510 -.04118616 . . 1 "3M India Ltd." 15544 510 .04037801 . . 1 "3M India Ltd." 15545 510 -.010900042 . . 1 "3M India Ltd." 15546 510 .005176115 . . 1 "3M India Ltd." 15547 510 -.003322259 . . 1 "3M India Ltd." 15550 510 .005666707 . . 1 "3M India Ltd." 15551 510 -.005634777 . . 1 "3M India Ltd." 15552 510 0 . . 1 "3M India Ltd." 15553 511 0 . . 1 "3M India Ltd." 15554 511 .009666646 . . 1 "3M India Ltd." 15557 511 .002806227 . . 1 "3M India Ltd." 15558 511 .0008230453 . . 1 "3M India Ltd." 15559 511 .009210486 . . 1 "3M India Ltd." 15560 511 -.022164237 . . 1 "3M India Ltd." 15561 511 .0025 . . 1 "3M India Ltd." 15564 511 -.0011637775 . . 1 "3M India Ltd." 15565 511 -.0013315376 . . 1 "3M India Ltd." 15566 511 0 . . 1 "3M India Ltd." 15568 511 .013666687 . . 1 "3M India Ltd." 15571 511 -.013482427 . . 1 "3M India Ltd." 15572 511 .01 . . 1 "3M India Ltd." 15573 511 -.003465306 . . 1 "3M India Ltd." 15574 511 .00049675076 . . 1 "3M India Ltd." 15575 511 .0043031704 . . 1 "3M India Ltd." 15578 511 . . . 1 "3M India Ltd." 15579 511 . . . 1 "3M India Ltd." 15580 511 .0008196721 . . 1 "3M India Ltd." 15581 511 -.0008190008 . . 1 "3M India Ltd." 15582 511 .036065575 . . 1 "3M India Ltd." 15585 512 -.003164557 . . 1 "3M India Ltd." 15586 512 -.004761905 . . 1 "3M India Ltd." 15587 512 .004784689 . . 1 "3M India Ltd." 15588 512 0 . . 1 "3M India Ltd." 15589 512 -.014603194 . . 1 "3M India Ltd." 15592 512 -.012564413 . . 1 "3M India Ltd." 15594 512 .01141925 . . 1 "3M India Ltd." 15595 512 . . . 1 "3M India Ltd." 15596 512 . . . 1 "3M India Ltd." 15599 512 0 . . 1 "3M India Ltd." 15600 512 .05919357 . . 1 "3M India Ltd." 15601 512 -.010202547 . . 1 "3M India Ltd." 15602 512 -.015230807 . . 1 "3M India Ltd." 15603 512 -.009842194 . . 1 "3M India Ltd." 15606 512 -.004891094 . . 1 "3M India Ltd." 15607 512 -.008720469 . . 1 "3M India Ltd." 15608 512 .005758118 . . 1 "3M India Ltd." 15609 512 .007474574 . . 1 "3M India Ltd." 15610 512 -.005209136 . . 1 "3M India Ltd." 15613 512 -.0003173789 . . 1 "3M India Ltd." 15614 513 -.012698413 . . 1 "3M India Ltd." 15616 513 .012861736 . . 1 "3M India Ltd." 15617 513 -.00952381 . . 1 "3M India Ltd." 15620 513 . . . 1 "3M India Ltd." 15621 513 . . . 1 "3M India Ltd." 15622 513 .010583767 . . 1 "3M India Ltd." 15623 513 -.0003173789 . . 1 "3M India Ltd." 15624 513 0 . . 1 "3M India Ltd." 15627 513 0 . . 1 "3M India Ltd." 15629 513 0 . . 1 "3M India Ltd." 15630 513 0 . . 1 "3M India Ltd." 15631 513 0 . . 1 "3M India Ltd." 15634 513 -.003174603 . . 1 "3M India Ltd." 15635 513 -.0031847134 . . 1 "3M India Ltd." 15636 513 .0006390166 . . end format %td date format %tm mdate
Comment