Reputation: 13
Noob coder here, so I would appreciate your help:)
Im trying to run the same regression with different y variables. Basically I need to run a results = lm(stock ~ beta, data=d) regression, but I have 103 different stocks to run the same regression with monthly data (103 stocks, 100 months per stock)
I need to regress the excess returns of 103 different stocks on the same beta (my X variable) for every regression. At the moment I am just changing the stock manually, but this is extremely time consuming and annoying.
Upvotes: 1
Views: 41
Reputation: 79228
lm
allows for multiple regressions all at once.
use
lm(as.matrix(stocks)~d$beta)
A quick example is to use the mtcars
dataset
lm(as.matrix(mtcars[-1])~mpg, mtcars)
Call:
lm(formula = as.matrix(mtcars[-1]) ~ mpg, data = mtcars)
Coefficients:
cyl disp hp drat wt qsec vs am gear carb
(Intercept) 11.26068 580.88382 324.08231 2.38249 6.04726 15.35477 -0.67817 -0.59149 2.50627 5.77880
mpg -0.25251 -17.42912 -8.82973 0.06043 -0.14086 0.12414 0.05553 0.04966 0.05880 -0.14765
Upvotes: 2