I want to use below code to generate monthly CAPM beta which is equal to beta coefficient of mkt obtained each month by regressing rt on mkt using twelve months daily rt and mkt data from months beginning t-11 and ending month t. However, before i use the code, I want to confirm that whether it is correctly specified. The code and data set example is appended below.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int stock_id str10 month str52 stock float(pr mk rf) 1 "29-06-2001" "3M India Ltd." 380.1 1050.43 .000190118 1 "02-07-2001" "3M India Ltd." 380 1044.7 .000190118 1 "03-07-2001" "3M India Ltd." 382 1016.12 .000190118 1 "04-07-2001" "3M India Ltd." 373 1012.19 .000189043 1 "05-07-2001" "3M India Ltd." 370 1016.32 .000189043 1 "06-07-2001" "3M India Ltd." 363 1008.44 .000189043 1 "09-07-2001" "3M India Ltd." 370.1 1005.61 .000189043 1 "10-07-2001" "3M India Ltd." 365 1015.86 .000189043 1 "11-07-2001" "3M India Ltd." 365 1023.1 .000189043 1 "12-07-2001" "3M India Ltd." . 1045.89 .000189043 1 "13-07-2001" "3M India Ltd." 379.8 1047.82 .000189043 1 "16-07-2001" "3M India Ltd." 374.5 1043.17 .000189043 1 "17-07-2001" "3M India Ltd." 384 1038.48 .000189043 1 "18-07-2001" "3M India Ltd." . 1035.52 .000191194 1 "19-07-2001" "3M India Ltd." 380 1029.28 .000191194 1 "20-07-2001" "3M India Ltd." 367 1021.48 .000191194 1 "23-07-2001" "3M India Ltd." . 1017.91 .000191194 1 "24-07-2001" "3M India Ltd." 364 1007.34 .000191194 1 "25-07-2001" "3M India Ltd." 362.1 992.87 .000190118 1 "26-07-2001" "3M India Ltd." 345 983.87 .000190118 1 "27-07-2001" "3M India Ltd." 335 985.08 .000190118 1 "30-07-2001" "3M India Ltd." . 997.06 .000190118 1 "31-07-2001" "3M India Ltd." 325.1 1007.38 .000190118 1 "01-08-2001" "3M India Ltd." 321.35 1002.07 .000187969 1 "02-08-2001" "3M India Ltd." 318 1007.21 .000187969 1 "03-08-2001" "3M India Ltd." 323 1016.31 .000187969 1 "06-08-2001" "3M India Ltd." 332.5 1016.84 .000187969 1 "07-08-2001" "3M India Ltd." 332 1009.8 .000187969 1 "08-08-2001" "3M India Ltd." 330 1005.47 .000186894 1 "09-08-2001" "3M India Ltd." 330 1005.16 .000186894 1 "10-08-2001" "3M India Ltd." 325.9 1001.29 .000186894 1 "13-08-2001" "3M India Ltd." 330 991.02 .000186894 1 "14-08-2001" "3M India Ltd." 325 1004.51 .000184742 1 "16-08-2001" "3M India Ltd." 320 1006.83 .000184742 1 "17-08-2001" "3M India Ltd." 320 998.73 .000184742 1 "20-08-2001" "3M India Ltd." 301.3 993.36 .000184742 1 "21-08-2001" "3M India Ltd." 309.55 998.08 .000184742 1 "23-08-2001" "3M India Ltd." 305 998.48 .000184742 1 "24-08-2001" "3M India Ltd." 302.5 1001.45 .000184742 1 "27-08-2001" "3M India Ltd." 315 1005.27 .000184742 1 "28-08-2001" "3M India Ltd." 315 1003.13 .000184742 1 "29-08-2001" "3M India Ltd." . 1001.18 .000183666 1 "30-08-2001" "3M India Ltd." 323 999.71 .000183666 1 "31-08-2001" "3M India Ltd." . 986.25 .000183666 1 "03-09-2001" "3M India Ltd." 311.05 976.87 .000183666 1 "04-09-2001" "3M India Ltd." 324 980.81 .000183666 1 "05-09-2001" "3M India Ltd." 321 976.21 .000183666 1 "06-09-2001" "3M India Ltd." 316.9 967.46 .000183666 1 "07-09-2001" "3M India Ltd." 318 968.13 .000183666 1 "10-09-2001" "3M India Ltd." 317 965.93 .000183666 1 "11-09-2001" "3M India Ltd." 310 959.32 .000183666 1 "12-09-2001" "3M India Ltd." 303.85 924.96 .000187969 1 "13-09-2001" "3M India Ltd." 305.4 915.84 .000187969 1 "14-09-2001" "3M India Ltd." 290 861.02 .000187969 1 "17-09-2001" "3M India Ltd." 257.3 804.92 .000187969 1 "18-09-2001" "3M India Ltd." 280 836.2 .000187969 1 "19-09-2001" "3M India Ltd." 290 840.08 .000193344 1 "20-09-2001" "3M India Ltd." 278.95 826.37 .000193344 1 "21-09-2001" "3M India Ltd." 272 792.18 .000193344 1 "24-09-2001" "3M India Ltd." 271 815.18 .000193344 1 "25-09-2001" "3M India Ltd." 270 807.94 .000193344 1 "26-09-2001" "3M India Ltd." 261.5 821.67 .000187969 1 "27-09-2001" "3M India Ltd." 260 825.81 .000187969 1 "28-09-2001" "3M India Ltd." 266 850.56 .000187969 1 "01-10-2001" "3M India Ltd." 276.5 844.2 .000187969 1 "03-10-2001" "3M India Ltd." 270 832.46 .000184742 1 "04-10-2001" "3M India Ltd." 263.8 842.15 .000184742 1 "05-10-2001" "3M India Ltd." . 844.87 .000184742 1 "08-10-2001" "3M India Ltd." 273.5 831.16 .000184742 1 "09-10-2001" "3M India Ltd." 270 842.27 .000184742 1 "10-10-2001" "3M India Ltd." 278 861.97 .000185818 1 "11-10-2001" "3M India Ltd." 270 875.14 .000185818 1 "12-10-2001" "3M India Ltd." 265.5 878.54 .000185818 1 "15-10-2001" "3M India Ltd." 262.2 880.39 .000185818 1 "16-10-2001" "3M India Ltd." 259.85 891.59 .000185818 1 "17-10-2001" "3M India Ltd." 260 906.58 .000187969 1 "18-10-2001" "3M India Ltd." 261.9 890.81 .000187969 1 "19-10-2001" "3M India Ltd." 260 899.6 .000187969 1 "22-10-2001" "3M India Ltd." 265 903.64 .000187969 1 "23-10-2001" "3M India Ltd." 265 916.9 .000187969 1 "24-10-2001" "3M India Ltd." 261.6 912.92 .000178282 1 "25-10-2001" "3M India Ltd." 263.25 909.88 .000178282 1 "29-10-2001" "3M India Ltd." 265.85 911.35 .000178282 1 "30-10-2001" "3M India Ltd." 265 895.86 .000178282 1 "31-10-2001" "3M India Ltd." 270 902.84 .000180436 1 "01-11-2001" "3M India Ltd." 274.9 916.37 .000180436 1 "02-11-2001" "3M India Ltd." 265.95 918.84 .000180436 1 "05-11-2001" "3M India Ltd." 270 919.12 .000180436 1 "06-11-2001" "3M India Ltd." 275 932.31 .000180436 1 "07-11-2001" "3M India Ltd." 270.25 920.84 .000180436 1 "08-11-2001" "3M India Ltd." 274.75 931.26 .000180436 1 "09-11-2001" "3M India Ltd." 271.5 934.92 .000180436 1 "12-11-2001" "3M India Ltd." 273 942.81 .000180436 1 "13-11-2001" "3M India Ltd." 285 937.24 .000180436 1 "14-11-2001" "3M India Ltd." 289.9 950.69 .000180436 1 "15-11-2001" "3M India Ltd." 290 968.45 .000180436 1 "19-11-2001" "3M India Ltd." 297.2 997.2 .000180436 1 "20-11-2001" "3M India Ltd." 288 986.23 .000180436 1 "21-11-2001" "3M India Ltd." 290 994.23 .000180436 1 "22-11-2001" "3M India Ltd." 288 1003.35 .000180436 end
Code:
gen date1=date(month,"DMY") format date1 %td drop month rename date1 date gen mdate= mofd(date) format mdate %tm bysort stock_id (date): gen rt_r =((pr[_n]-pr[_n-1])/pr[_n-1]) bysort stock_id (date):gen mkt_r =((mk[_n]-mk[_n-1])/mk[_n-1]) gen rt = rt_r-rf gen mkt = mkt_r-rf gen month = month(date) gen year = year(date) rangestat (reg) rt mkt, interval(mdate -11 0) by(stock_id) collapse(mean) mdate reg_nobs stock_id b_mkt, by(stock year month) drop if mdate<ym(2002,6) drop if mdate>ym(2003,5) replace b_mkt =. if reg_nobs<200 rename b_mkt beta
Comment