Экспорт комбинированных таблиц при использовании опробита - PullRequest
2 голосов
/ 10 мая 2019

Я выполняю заказанный пробит с четырьмя уровнями (много, немного, немного, совсем нет) для женской переменной и некоторыми элементами управления:

* Baseline only
eststo, title ("OProbit1"): /*quietly*/ oprobit retincome_worry i.female  $control_socio, vce(robust)
estimate store OProbit1

* Baseline + Health Controls

eststo, title ("OProbit3"): oprobit retincome_worry i.female  $control_socio $control_health, vce(robust)
estimate store OProbit3

Я делаю это для marginalЭффекты внутренней переменной:

* TABLE BASELINE

estimate restore OProbit1
margins, dydx(i.female) predict (outcome(1)) atmeans post
outreg using results\Reg_margins\Reg2.tex, noautosumm replace rtitle(A lot) ctitle(Social Controls)  title(Worry about Retirement Income)

estimate restore OProbit1
margins, dydx(i.female) predict (outcome(2)) atmeans post
outreg using results\Reg_margins\Reg2.tex, noautosumm append rtitle(Somewhat)  

estimate restore OProbit1
margins, dydx(i.female) predict (outcome(3)) atmeans post
outreg using results\Reg_margins\Reg2.tex, noautosumm append rtitle(Little)  

estimate restore OProbit1
margins, dydx(i.female) predict (outcome(4)) atmeans post
outreg using results\Reg_margins\Reg2.tex, noautosumm append rtitle(Not at all) tex 

* TABLE BASELINE + HEALTH

estimate restore OProbit3
margins, dydx(i.female) predict (outcome(1)) atmeans post 
outreg using results\Reg_margins\Reg3.tex, noautosumm replace rtitle(A lot) ctitle(Baseline and Health) title(Worry about Retirement Income)

estimate restore OProbit3
margins, dydx(i.female) predict (outcome(2)) atmeans post
outreg using results\Reg_margins\Reg3.tex, append noautosumm rtitle(Somewhat)  

estimate restore OProbit3
margins, dydx(i.female) predict (outcome(3)) atmeans post
outreg using results\Reg_margins\Reg3.tex, append noautosumm rtitle(Little) 

estimate restore OProbit3
margins, dydx(i.female) predict (outcome(4)) atmeans post
outreg using results\Reg_margins\Reg3.tex, append noautosumm rtitle(Not at all) tex

В настоящее время у меня есть четыре таблицы (см. примеры для двух из них), каждая с именем столбца, которое является элементами управлениявключены в модель и четыре строки с каждым уровнем:

Table with Baseline Controls

Table with Baseline and Health Controls

Как я могу собрать все это в одной таблице, сохраняя четырестроки и добавление дополнительных столбцов?

1 Ответ

1 голос
/ 10 мая 2019

Вы можете получить желаемый результат, используя команду от сообщества esttab.

Сначала определите программу appendmodels ( получено отсюда ):

capt prog drop appendmodels
*! version 1.0.0  14aug2007  Ben Jann
program appendmodels, eclass
    // using first equation of model
    version 8
    syntax namelist
    tempname b V tmp
    foreach name of local namelist {
        qui est restore `name'
        mat `tmp' = e(b)
        local eq1: coleq `tmp'
        gettoken eq1 : eq1
        mat `tmp' = `tmp'[1,"`eq1':"]
        local cons = colnumb(`tmp',"_cons")
        if `cons'<. & `cons'>1 {
            mat `tmp' = `tmp'[1,1..`cons'-1]
        }
        mat `b' = nullmat(`b') , `tmp'
        mat `tmp' = e(V)
        mat `tmp' = `tmp'["`eq1':","`eq1':"]
        if `cons'<. & `cons'>1 {
            mat `tmp' = `tmp'[1..`cons'-1,1..`cons'-1]
        }
        capt confirm matrix `V'
        if _rc {
            mat `V' = `tmp'
        }
        else {
            mat `V' = ///
            ( `V' , J(rowsof(`V'),colsof(`tmp'),0) ) \ ///
            ( J(rowsof(`tmp'),colsof(`V'),0) , `tmp' )
        }
    }
    local names: colfullnames `b'
    mat coln `V' = `names'
    mat rown `V' = `names'
    eret post `b' `V'
    eret local cmd "whatever"
end

Далее запустите следующее (здесь я использую игрушечный набор данных Stata fullauto):

webuse fullauto, clear
estimates clear

forvalues i = 1 / 4 {
    oprobit rep77 i.foreign
    margins, dydx(foreign) predict (outcome(`i')) atmeans post
    estimate store OProbit1`i'
}

appendmodels OProbit11 OProbit12 OProbit13 OProbit14 
estimates store result1

forvalues i = 1 / 4 {
    oprobit rep77 i.foreign length mpg
    margins, dydx(foreign) predict (outcome(`i')) atmeans post
    estimate store OProbit2`i'
}

appendmodels OProbit21 OProbit22 OProbit23 OProbit24 
estimates store result2

forvalues i = 1 / 4 {
    oprobit rep77 i.foreign trunk weight
    margins, dydx(foreign) predict (outcome(`i')) atmeans post
    estimate store OProbit3`i'
}

appendmodels OProbit31 OProbit32 OProbit23 OProbit34 
estimates store result3

forvalues i = 1 / 4 {
    oprobit rep77 i.foreign price displ
    margins, dydx(foreign) predict (outcome(`i')) atmeans post
    estimate store OProbit4`i'
}

appendmodels OProbit41 OProbit42 OProbit43 OProbit44 
estimates store result4

Наконец, посмотрите результаты:

esttab result1 result2 result3 result4, keep(1.foreign) varlab(1.foreign " ") ///
labcol2("A lot" "Somewhat" "A little" "Not at all") gaps noobs nomtitles

-------------------------------------------------------------------------------------
                   (1)             (2)             (3)             (4)   
-------------------------------------------------------------------------------------
A lot          -0.0572         -0.0677         -0.0728         -0.0690   
               (-1.83)         (-1.67)         (-1.81)         (-1.67)   
Somewhat        -0.144**        -0.247***       -0.188**        -0.175*  
               (-2.73)         (-3.54)         (-2.86)         (-2.47)   
A little        -0.124          -0.290**        -0.290**        -0.163   
               (-1.86)         (-3.07)         (-3.07)         (-1.74)   
Not at all       0.198**         0.351***        0.252**         0.237*  
                (2.64)          (3.82)          (2.95)          (2.55)   
-------------------------------------------------------------------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001

Вы можете установить esttab, введя в командной строке Stata следующее:

ssc install estout
...