Hello,
My objective is to create 3 new variables that return the coefficients from the following regression: reti,t= ai+B1i RMRFt+B2iSMBt+B3iHMLt+ei,t. So the 3 variables should return B1, B2 and B3.
This regression should be done by permno (indicative of each stock) in every month t over the period t-36 to t-1. The regression should not return anything if there is any missing value in the range t-36 to t-1.
I believe this is basically a simple regression over a 36-month rolling window. But I do not know how to do it.. Hope you can help me.
input double permno long date double(ret MktRF SMB HML RF)
10000 312 . .65 1.22 .56 .56
10000 313 -.2571428716182709 7.13 -.65 -.93 .53
10000 314 .36538460850715637 4.88 -.51 -.47 .6
10000 315 -.09859155118465424 -1.31 2.84 -2.91 .52
10000 316 -.22265625 4.62 -1.31 -.11 .49
10000 317 -.005025125574320555 1.03 -.9 1.39 .52
10000 318 -.08080808073282242 -6.45 -3.38 4.77 .52
10000 319 -.6153846383094788 6.07 -4.18 3.51 .46
10000 320 -.05714285746216774 -8.6 2.28 3.19 .45
10000 321 -.24242424964904785 4.66 -2.49 -1.34 .46
10000 322 .05999999865889549 1.17 -1.92 -.05 .39
10000 323 -.37735849618911743 -3.27 .08 .33 .49
10000 324 -.21212121844291687 12.47 -1.8 -3.17 .42
10000 325 0 4.39 3.49 -5.98 .43
10000 326 -.38461539149284363 1.64 .37 1.64 .47
10000 327 -.0625 -2.11 -1.7 -.32 .44
10000 328 -.06666667014360428 .11 -.52 .12 .38
10000 329 . 3.94 -2.19 1.06 .48
10001 312 . .65 1.22 .56 .56
10001 313 .020408162847161293 7.13 -.65 -.93 .53
10001 314 .025200003758072853 4.88 -.51 -.47 .6
10001 315 .009900989942252636 -1.31 2.84 -2.91 .52
10001 316 -.009803921915590763 4.62 -1.31 -.11 .49
10001 317 -.013069307431578636 1.03 -.9 1.39 .52
10001 318 -.010204081423580647 -6.45 -3.38 4.77 .52
10001 319 .07216494530439377 6.07 -4.18 3.51 .46
10001 320 -.003076923545449972 -8.6 2.28 3.19 .45
10001 321 .03921568766236305 4.66 -2.49 -1.34 .46
10001 322 .056603774428367615 1.17 -1.92 -.05 .39
10001 323 .014999999664723873 -3.27 .08 .33 .49
10001 324 -.0357142873108387 12.47 -1.8 -3.17 .42
10001 325 -.07407407462596893 4.39 3.49 -5.98 .43
10001 326 .03680000081658363 1.64 .37 1.64 .47
10001 327 -.03921568766236305 -2.11 -1.7 -.32 .44
10001 328 -.0714285746216774 .11 -.52 .12 .38
10001 329 .051428571343421936 3.94 -2.19 1.06 .48
10001 330 .021276595070958138 3.85 -.63 .71 .46
10001 331 .0833333358168602 3.52 -.75 -.93 .47
10001 332 -.02230769209563732 -2.59 .53 .28 .45
10001 333 .019999999552965164 -23.24 -8.42 4.23 .6
10001 334 -.029411764815449715 -7.77 2.76 3.08 .35
10001 335 -.03353535383939743 6.81 .13 -4.45 .39
10001 336 .06382978707551956 4.21 -.7 5.17 .29
10001 337 .07999999821186066 4.75 3.35 -1.65 .46
10001 338 -.07629629969596863 -2.27 6.15 .75 .44
10001 339 .030612245202064514 .56 .96 1.68 .46
10001 340 .019801979884505272 -.29 -2.65 2.28 .51
10001 341 -.01203883532434702 4.79 2.12 -1.11 .49
10001 342 .029999999329447746 -1.25 -.21 2.27 .51
10001 343 .029126213863492012 -3.31 .08 2.08 .59
10001 344 -.021132076159119606 3.3 -1.26 -.69 .62
My objective is to create 3 new variables that return the coefficients from the following regression: reti,t= ai+B1i RMRFt+B2iSMBt+B3iHMLt+ei,t. So the 3 variables should return B1, B2 and B3.
This regression should be done by permno (indicative of each stock) in every month t over the period t-36 to t-1. The regression should not return anything if there is any missing value in the range t-36 to t-1.
I believe this is basically a simple regression over a 36-month rolling window. But I do not know how to do it.. Hope you can help me.
input double permno long date double(ret MktRF SMB HML RF)
10000 312 . .65 1.22 .56 .56
10000 313 -.2571428716182709 7.13 -.65 -.93 .53
10000 314 .36538460850715637 4.88 -.51 -.47 .6
10000 315 -.09859155118465424 -1.31 2.84 -2.91 .52
10000 316 -.22265625 4.62 -1.31 -.11 .49
10000 317 -.005025125574320555 1.03 -.9 1.39 .52
10000 318 -.08080808073282242 -6.45 -3.38 4.77 .52
10000 319 -.6153846383094788 6.07 -4.18 3.51 .46
10000 320 -.05714285746216774 -8.6 2.28 3.19 .45
10000 321 -.24242424964904785 4.66 -2.49 -1.34 .46
10000 322 .05999999865889549 1.17 -1.92 -.05 .39
10000 323 -.37735849618911743 -3.27 .08 .33 .49
10000 324 -.21212121844291687 12.47 -1.8 -3.17 .42
10000 325 0 4.39 3.49 -5.98 .43
10000 326 -.38461539149284363 1.64 .37 1.64 .47
10000 327 -.0625 -2.11 -1.7 -.32 .44
10000 328 -.06666667014360428 .11 -.52 .12 .38
10000 329 . 3.94 -2.19 1.06 .48
10001 312 . .65 1.22 .56 .56
10001 313 .020408162847161293 7.13 -.65 -.93 .53
10001 314 .025200003758072853 4.88 -.51 -.47 .6
10001 315 .009900989942252636 -1.31 2.84 -2.91 .52
10001 316 -.009803921915590763 4.62 -1.31 -.11 .49
10001 317 -.013069307431578636 1.03 -.9 1.39 .52
10001 318 -.010204081423580647 -6.45 -3.38 4.77 .52
10001 319 .07216494530439377 6.07 -4.18 3.51 .46
10001 320 -.003076923545449972 -8.6 2.28 3.19 .45
10001 321 .03921568766236305 4.66 -2.49 -1.34 .46
10001 322 .056603774428367615 1.17 -1.92 -.05 .39
10001 323 .014999999664723873 -3.27 .08 .33 .49
10001 324 -.0357142873108387 12.47 -1.8 -3.17 .42
10001 325 -.07407407462596893 4.39 3.49 -5.98 .43
10001 326 .03680000081658363 1.64 .37 1.64 .47
10001 327 -.03921568766236305 -2.11 -1.7 -.32 .44
10001 328 -.0714285746216774 .11 -.52 .12 .38
10001 329 .051428571343421936 3.94 -2.19 1.06 .48
10001 330 .021276595070958138 3.85 -.63 .71 .46
10001 331 .0833333358168602 3.52 -.75 -.93 .47
10001 332 -.02230769209563732 -2.59 .53 .28 .45
10001 333 .019999999552965164 -23.24 -8.42 4.23 .6
10001 334 -.029411764815449715 -7.77 2.76 3.08 .35
10001 335 -.03353535383939743 6.81 .13 -4.45 .39
10001 336 .06382978707551956 4.21 -.7 5.17 .29
10001 337 .07999999821186066 4.75 3.35 -1.65 .46
10001 338 -.07629629969596863 -2.27 6.15 .75 .44
10001 339 .030612245202064514 .56 .96 1.68 .46
10001 340 .019801979884505272 -.29 -2.65 2.28 .51
10001 341 -.01203883532434702 4.79 2.12 -1.11 .49
10001 342 .029999999329447746 -1.25 -.21 2.27 .51
10001 343 .029126213863492012 -3.31 .08 2.08 .59
10001 344 -.021132076159119606 3.3 -1.26 -.69 .62
Comment