obtaining average coefficients and adj. R^2 from multiple pooled regressions using lapply

孤者浪人 提交于 2019-12-06 06:16:12

Try

 COEFTEST<-lapply(myregression, function(x) coeftest(x, vcov=vcovSCC(x, type="HC3", maxlag=4)))

Thsi will give you a list of coeftest-outputs for each regression, which you can then use in whatever way you want.

As a sidenote, make sure that whatever you do with this output makes sense. Taking the mean of an coeftest-output is not obvously sensible to me. If you want to have the average over all coefficients, try something like

 mean(sapply(COEFTEST, function(x)  x["capital", "Estimate"]))

Here, sapply retrieves all estimates for the variable capital from the COEFTEST outputs and puts them into a vector.

To access other elements, it is helpful to look at the structure of the objects using str(). For instance, str(summary(myregression[[1]])) reveals that the r-squares are saved under the name r.squared. These you can access using e.g. summary(myregression[[1]])$r.squared for the first regression output. Automating this, you can again use a construct as above, e.g.

 sapply(myregression, function(x) summary(x)$r.squared)
landroni

There is a nicer way to obtain average coefficients (technically known as Mean Group estimators) using pmg() in plm. And from the looks of it, you are trying to estimate Fama-MacBeth regressions and SEs.

require(foreign)
require(plm)
require(lmtest)
test <- read.dta("http://www.kellogg.northwestern.edu/faculty/petersen/htm/papers/se/test_data.dta")
fpmg <- pmg(y~x, test, index=c("year","firmid")) ##Fama-MacBeth

> ##Fama-MacBeth
> coeftest(fpmg)

t test of coefficients:

            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.031278   0.023356  1.3392   0.1806    
x           1.035586   0.033342 31.0599   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

For further details see Fama-MacBeth and Cluster-Robust (by Firm and Time) Standard Errors in R.

See also:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!