-1

Current code:

alpha_function <- function(x){
  group_by(wficn, caldt) %>%
  lm(mktrf~excess_return, data = CRSP_database) %>%
  tidy() %>%
  [[1]]$estimate
  return()
}

Data: date, fundno, mtna, mret, mnav, mktrf, smb, hml, umd, rf

Needed is a database showing the total alpha per fund per year. Or the beta of one fundno per year.

Phil
  • 7,287
  • 3
  • 36
  • 66
  • Can you rephrase? I'm having trouble parsing out your code and what you're asking for. – Phil Jun 08 '22 at 20:15
  • We have a data base in which we need to find the beta's and alpha's for each separate fund for each seperate year. Currently using the following code: Returns_Database <- CRSP_Database %>% select(Wficn, caldt, Excess_Return, mktrf, smb, hml, umd, rf, mret ) %>% nest(data = !c("Wficn", "caldt")) %>% mutate(model = map(data ~ alpha_function)) %>% mutate( model, tidy)%>% unnest(model) – Thomas Hollemans Jun 09 '22 at 09:21
  • It doesn't make sense to have a `!` in the `nest()` call. – Phil Jun 09 '22 at 14:17

1 Answers1

0

Try the below, but again it would be easier to help if you could provide an example of your data set to test it on.

alpha_function <- function(x){
  CRSP_database %>%
    group_by(wficn, caldt) %>%
    lm(mktrf~excess_return, data = .x) %>%
    tidy() %>%
    pluck("estimate")
}
Phil
  • 7,287
  • 3
  • 36
  • 66