0

Hello I have 9 dataframes that look like this:


    RET         mktrf    smb      hml    rf
1   0.012930    0.0120  0.0005  -0.0003 0.00018
2   0.001054    -0.0023 -0.0098 0.0019  0.00018
3   0.020356    0.0121  0.0012  -0.0028 0.00018
4   -0.002522   -0.0085 -0.0011 -0.0015 0.00018
5   -0.031034   -0.0233 -0.0007 -0.0040 0.00018
6   0.028470    0.0213  0.0012  0.0001  0.00018

Above is an example of one of them--all of them are in the exact same format.

I need the same regression for them I tried this:


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


# for loop for normal returns
fama_summaries=list()
for (i in dflist){
  ri_rf = (i[,1]-i[,5])
  capm = (i[,2]-i[,5])
  fama=lapply(i,function(x) lm(ri_rf ~ smb + hml + capm, data =i))
  append(fama_summaries,values=summary(fama))
}

But I'm not getting any results. I need the summaries and the coefficients saved for each regression so I can use them later... Can someone help me out?

Melody
  • 11
  • 3
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Pictures of data are not helpful because we can't copy/paste them into R. – MrFlick Oct 28 '21 at 04:29
  • edited! @MrFlick – Melody Oct 28 '21 at 04:54
  • `append()` doesn't modify in place. You need to assign it somewhere like `fama_summaires <- append(fama_summaries,values=summary(fama))`. – MrFlick Oct 28 '21 at 04:55
  • @MrFlick I end up with something like [[1]] [1] "12" [[2]] [1] "12" [[3]] [1] "12" [[4]] [1] "12" [[5]] [1] "12" – Melody Oct 28 '21 at 05:02
  • Well, you are taking the `summary()` of the list, not of each element in the list. You can move the summary into your first `lapply` or you can run another one `lapply(fama, summary)` – MrFlick Oct 28 '21 at 05:10

0 Answers0