How to include AIC in table after margins postesti

2019-08-22 08:10发布

I have a GLM model, which I estimate in Stata. The coefficients of interest are the marginal effects, which I get with margins command.

However, the postestimation table does not include summary statistics like AIC, which I would like to have there.

I have tried this by writing an auxiliary program getAIC:

program getAIC
    estat ic
    matrix list r(S)
    matrix S = r(S)
    scalar aic = S[1,5]
end

The estimation would then proceed like this:

 qui glm y x, fa(bin) link(probit)
 getAIC
 qui margins, dydx(x) post
 estadd loc AIC aic

And the output command is:

 esttab using output.tex, s(aic, fmt(0))

However, I don't have AIC in the results table.

Any ideas how to do this?

标签: stata
1条回答
相关推荐>>
2楼-- · 2019-08-22 09:07

You need to return the scalar aic from your program getAIC and use it accordingly.

The following works for me:

program getAIC, rclass
    estat ic
    matrix list r(S)
    matrix S = r(S)
    scalar aic = S[1,5]
    return scalar aic = aic
end

sysuse auto, clear

glm foreign price, fa(bin) link(probit)

getAIC
local AIC = round(`r(aic)', .01)

margins, dydx(price) post

estadd local AIC `AIC'

esttab using output, s(AIC) replace

type output.txt
----------------------------
                      (1)   

----------------------------
price          0.00000766   
                   (0.43)   
----------------------------
AIC                 93.89   
----------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001
查看更多
登录 后发表回答