Looped stock price regression with NA's R

Viewed 15

I am trying to regress the impact of two independent variables (x1, x2) on each dependent variable in my sample (n = 13095). The dependent variables are daily stock returns over ~15 years. However, as not all stocks existed for the whole timespan, I have a lot of columns in my dataset with NA's. The independent variables cover the whole timespan without missing variables.

Currently, I tried running the regression as following:

n <- 13095
my_lms <- lapply(1:n, function(x) lm(y[,x] ~ x1 + x2))

By running this, I get the following error due to the NA's in my dependent variables: Fehler in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in 'y'

Is there a way how I can loop my regression with dependent variables with different sizes?

Happy to provide a sample of my data if it would help to solve my issue. Your support is truly appreciated, thanks a lot in advance!

0 Answers
Related