0

I wish to regress certain factor exposures calculated for a portfolio on that portfolios returns over 550 months (monthly observations). Fama-macbeth regression.

So essentially, regressing 550 return observations on "constant," factor exposures previously calculated. My loop thus far is as follows

'''

# Second Regression
library(sandwich)
library(broom)
library(tibble)

#Chose file containing factor exposures (note: data columns = exposures, rows = portfolios) f <- file.choose() betas <- read.csv(f)

BTM2R <- betas[1, 3]
BIPR <- betas[1, 4]
BInfR <- betas[1, 5]
BUnR <- betas[1, 6]
BOilR <- betas[1, 7]

#Chose file containing return data (columns = portfolios, rows = monthly return observations) f <- file.choose() retur <- read.csv(f)

for (i in 1:nrow(retur)){
  mod <- lm(data = retur, retur[[i,1]]~BTM2R+BIPR+BInfR+BUnR+BOilR)
  print(mod$coefficients)
}

'''

(I also wish to develop this loop further so that after running this regression for each portfolio, it is run for the next portfolio, such that the column number in "return," = j??? But will first address my current problem)

My current problem is that when I run the regression, all coefficient values return "NA," aside from the intercept, which returns a value. To confuse matters further, the intercept does not equal the return value at time = t, which, although the regression results would still obviously be incorrect, one would expect if all other coefficients return "NA,"

  • 1
    You can't pass retur[[i,1]] like that, you have to construct it using as.formula. – user2974951 May 16 '22 at 11:25
  • Perhaps this approach can be adapted to suit? https://stackoverflow.com/questions/65603511/fitting-several-regression-models-by-changing-only-one-independent-variable-with – jared_mamrot May 16 '22 at 11:33

0 Answers0