Hello stackexchange community!

I am new to R and econometrics and and stuck in a step of the fama-macbeth (1973) regression, in which risk premia of stocks are estimated with a two-step regression procedure.

The first regression looks like the following:

Rit = αi + βiRmt + εit ......(1)

where i = 1,...,20 stocks and Rm is the return of the market index (often referred to as factor in regressions)

The β in here, of which I have 20 (one for each stock), is the coefficient I want to use in the second regression, which is a cross-sectional regression:

Rit = γt βˆi + αit .............(2)

where again i = 1,...,20 stocks. I am supposed to get one γt (risk premium) per day(4500) and 20 αit (pricing errors) per day.

Now to my issue: The first regression was no problem. I have one .xts object (stocks.returns) with 20 stocks in the columns and 4500 rows, which are daily returns of each stock. Then I have another .xts object (index.returns) with the same attributes, but just one column which is the market index. With this data I run the following codes in order to get the betas:

all.betas <- coef(lm(stocks.returns ~ index.returns))
all.betas <- all.betas[2,1:20]

now I have a numeric vector with all 20 betas (removed the intercept) per stock and I want to run the second (2) regression and am trying the code:

summary(lm(stocks.returns ~ all.betas))

However, R keeps giving me this error:

Error in model.frame.default(formula = stocks.returns ~ all.betas, drop.unused.levels = TRUE) : variable lengths differ (found for 'all.betas')

I need to run a regression with all 20 stock returns against all 20 betas on each day (4500). I do not know how to structure this regression model/code.

I have been trying and searching for days now. Please help me. Any hints, errors I made, formulas I could try, literature, links, keywords etc. are highly appreciated!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.