I have two datasets "bear" and "frog" and I am trying to write a function, which would take columns one by one from "bear" as dependent variable in linear regression with same regressors in all cases, print the name of the column in each case and the summary of linear regression with coefficients, standard errors, t-value, R squared and residual standard errors.I want to get 25 separate outputs
I tried the following code
print(lm(bear[,i]~frog$MK_RF+frog$SMB+frog$HML))
print(colnames(bear[,i]))
summary (lm(bear[,i]~frog$Mkt.RF+frog$SMB+frog$HML))}
I wrote this function, but instead of column name i get NULL, and the summary only shows coefficients, no error message. For reproductible examples:
# dput(head(frog, 10))
frog <- structure(list(date = c(192607L, 192608L, 192609L, 192610L, 192611L,
192612L, 192701L, 192702L, 192703L, 192704L), Mkt.RF = c(2.96,
2.64, 0.36, -3.24, 2.53, 2.62, -0.06, 4.18, 0.13, 0.46), SMB = c(-2.3,
-1.4, -1.32, 0.04, -0.2, -0.04, -0.56, -0.1, -1.6, 0.43), HML = c(-2.87,
4.19, 0.01, 0.51, -0.35, -0.02, 4.83, 3.17, -2.67, 0.6), RF = c(0.22,
0.25, 0.23, 0.32, 0.31, 0.28, 0.25, 0.26, 0.3, 0.25)), row.names = c(NA,
10L), class = "data.frame")
and for the bear dataset
# dput(head(bear[, 1:3], 10))
bear <- structure(list(date = c(192607L, 192608L, 192609L, 192610L, 192611L,
192612L, 192701L, 192702L, 192703L, 192704L), SMALL.LoBM = c(3.5582,
-2.4574, -6.4413, -8.9441, 3.1644, 13.6658, 0.1974, 2.2284, 6.0998,
5.5863), ME1.BM2 = c(-0.6319, -8.9775, -0.5289, -4.0732, 6.3376,
-2.2572, -8.5499, -0.5649, -2.0464, 7.5611)), row.names = c(NA,
10L), class = "data.frame")