I have a panel data set like the following:
id date1 Returns Mkt.RF SMB.y HML.y RMW.y CMA.y RF.y
1 LP60068503 200002 3.9487727 5.95 0.47 -9.00 3.25 -7.18 0.43
2 LP60068503 200003 4.6201232 0.66 -5.04 3.10 -2.74 4.82 0.47
3 LP60068503 200004 -1.2757605 -5.58 -4.37 5.67 -1.08 1.22 0.46
4 LP60068503 200005 -1.3916501 -0.08 0.18 6.05 -3.30 4.84 0.50
5 LP60068503 200006 -2.4193548 0.67 0.50 2.94 -3.15 1.10 0.40
6 LP60068503 200007 0.8264463 -1.58 -0.71 3.25 -0.19 -0.10 0.48
id date1 Returns Mkt.RF SMB.y HML.y RMW.y CMA.y RF.y
340373 LP65117791 201207 3.4376360 0.56 -1.38 -2.57 2.29 -2.04 0.00
340374 LP65117791 201208 0.7893412 4.51 0.06 3.38 -1.68 1.45 0.01
340375 LP65117791 201209 0.2556494 3.49 1.65 2.33 -1.52 0.69 0.01
340376 LP65117791 201210 -1.0310320 1.67 -0.61 2.06 -0.93 -0.15 0.01
340377 LP65117791 201211 0.3411351 2.28 -2.40 -0.55 0.62 -0.80 0.01
340378 LP65117791 201212 0.7903986 3.38 2.48 3.09 -0.53 0.89 0.01
I would like to calculate the following rolling regression with three independet variables and get the alpha (a) intercept in a new column.
Returns ~ a + ß1*Mkt.RF + ß3*SMB.y + ß3*HML.y + e
The width window should be 36 months.
Using the rollRegres function works with one independent variable but I would like to know how to adjust this package to three independent variables. The code for getting the alpha intercept in a new column with one dependent variable would look like this:
Returns ~ a + ß1*Mkt.RF + e
dt[, alpha:=
roll_regres.fit(x = cbind(1, .SD[["Mkt.RF"]]), y = .SD[["return"]],
width = 36L)$coefs[, 1],
by = id]
So I'd like to know how to adjust this to three or more independent variables.