library(gmm) library(car) library(texreg) library(stargazer) # illustrate the use of two packages for writing to tables outdir <- "../../results/2020_09_gmm_us/" source("/home/bernt/data/2020/french_us_data/read_5_industries.R") source("/home/bernt/data/2020/french_us_data/read_3_pricing_factors.R") # then take 5 portfolios, start in 1990 industries <- names(FF5IndusEW) eRindus <-FF5IndusEW-RF eRi <- window(eRindus,start=c(1990,1)) data <- merge(eRi,RMRF,all=FALSE) # estimate as separate linear regressions eRi <- as.matrix(data[,1:5]) eRm <- as.matrix(data[,6]) summary(lm(eRi~eRm)) results <- list(lm(eRi[,1]~eRm),lm(eRi[,3]~eRm),lm(eRi[,3]~eRm),lm(eRi[,4]~eRm),lm(eRi[,5]~eRm)) ofilename <- paste0(outdir,"linear_regressions_5_industries.tex") stargazer(results, out=ofilename, column.labels=industries, float=FALSE, omit.stat=c("rsq","f","ser")) # estimate as a joint gmm system res <- gmm(eRi~eRm,x=eRm) summary(res) ofilename <- paste0(outdir,"gmm_5_industries.tex") texreg(res, table=FALSE, digits=3, file=ofilename) # test the joint hypothesis that all intercepts are zero R <- cbind(diag(5),matrix(0,5,5)) c <- rep(0,5) hyptest <- linearHypothesis(res,R,c,test="F") ofilename <- paste0(outdir,"gmm_5_industries_hypothesis_test.tex") stargazer(hyptest, out=ofilename, header=FALSE, omit.stat=c("rsq","f","ser"))