How to include AIC in table after margins postestimation results

拈花ヽ惹草 提交于 2019-12-20 06:34:35

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/51046495/how-to-include-aic-in-table-after-margins-postestimation-results

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