0

Hello I need to know how to apply a for loop regression over separate dataframes. I started by making a list of dataframes

dflist = c(cvx,csco,trv,unh,gs,nke,v,aapl,wba)

The response variable is ri_rf and the explanatory variables are smb,hml,capm.

I've already calculated smb, hml, capm, ri_rf and have them laid out from stock 1 to stock 12. I just need to regress for each stock!

I need the equation

lm(ri_rf ~ smb, hml,capm)

Can someone please help me out!!! Thanks

1 Answer 1

1

Store the dataframes in a list and apply lm for each dataframe using lapply -

dflist = list(cvx,csco,trv,unh,gs,nke,v,aapl,wba)
result <- lapply(dflist, function(x) lm(ri_rf ~ smb + hml + capm, x))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.