0

複数の変数の双方向度数分布表を表示する表を作成しようとしています。ロジックは、各変数が同じバイナリ インジケーターによって集計されるということです。

コミュニティが提供する一連のコマンドtexを使用して、出力をファイルに送信したいと考えています。ただし、各クロス集計は新しい列に表示されます。estout

次の再現可能なおもちゃの例を考えてみましょう。

sysuse auto
eststo clear 

eststo: estpost tab headroom foreign, notot
eststo: estpost tab trunk foreign, notot

esttab, c(b) unstack wide collabels(N)

----------------------------------------------------------------
                      (1)                       (2)             

                 Domestic      Foreign     Domestic      Foreign
                        N            N            N            N
----------------------------------------------------------------
1_missing_5             3            1                          
2                      10            3                          
2_missing_5             4           10                          
3                       7            6                          
3_missing_5            13            2                          
4                      10            0                          
4_missing_5             4            0                          
5                       1            0            0            1
6                                                 0            1
7                                                 3            0
8                                                 2            3
9                                                 3            1
10                                                3            2
11                                                4            4
12                                                1            2
13                                                4            0
14                                                1            3
15                                                2            3
16                                               10            2
17                                                8            0
18                                                1            0
20                                                6            0
21                                                2            0
22                                                1            0
23                                                1            0
----------------------------------------------------------------
N                      74                        74             
----------------------------------------------------------------

列が 2 つだけになるように出力を「整列」する方法はありDomesticますForeignか?

4

2 に答える 2

1

tex ファイルに出力する場合、1 つの解決策appendesttab. したがって、あなたの場合は次のようになります。

sysuse auto
eststo clear 
estpost tab headroom foreign, notot
eststo tab1
estpost tab trunk foreign, notot
eststo tab2
esttab tab1 using outputfile.tex, c(b) unstack wide collabels(N) replace
esttab tab2 using outputfile.tex, c(b) unstack wide collabels(N) append

もっと洗練された解決策もあると思いますが、これは一般的に実装が非常に簡単です。するときappendは、さまざまな列ヘッダーを削除するために一連のオプションを指定する必要がある可能性があります(のデフォルトでは、これらのヘッダーのほとんどが不要であると想定されているため、の代わりにestout調べる価値があるかもしれません)。estoutesttab

于 2013-12-15T21:36:46.827 に答える
1

目的の出力を生成するには、結果を積み重ねる必要があります。

最初にプログラム を定義します。これは、モデルをスタックするための Ben Jann のプログラムを簡単append_tabsに変更したバージョンです。appendmodels

program append_tabs, eclass
    version 8
    syntax namelist
    tempname b tmp
    local i 0
    foreach name of local namelist {
        qui est restore `name'
        foreach x in Domestic Foreign {
            local ++i
            mat `tmp'`i' = e(b)
            mat li `tmp'`i'
            mat `tmp'`i' = `tmp'`i'[1,"`x':"]
            local cons = colnumb(`tmp'`i',"_cons")
            if `cons'<. & `cons'>1 {
                mat `tmp'`i' = `tmp'`i'[1,1..`cons'-1]
            }
            mat li `tmp'`i'
            mat `b'`i' = `tmp'`i''
            mat li `b'`i'    
        }
    }
    mat `b'D = `b'1 \ `b'3
    mat `b'F = `b'2 \ `b'4
    mat A = `b'D , `b'F
    ereturn matrix results = A
    eret local cmd "append_tabs"
end

次に集計を実行し、以下を使用して結果を積み重ねますappend_tabs

sysuse auto, clear
estimates store clear

estpost tabulate headroom foreign, notot
estimates store one 

estpost tabulate trunk foreign, notot
estimates store two

append_tabs one two

最後に、結果を確認します。

esttab e(results), nonumber mlabels(none) eqlabels(none) collabels("Domestic" "Foreign")

--------------------------------------
                 Domestic      Foreign
--------------------------------------
1_missing_5             3            1
2                      10            3
2_missing_5             4           10
3                       7            6
3_missing_5            13            2
4                      10            0
4_missing_5             4            0
5                       1            0
5                       0            1
6                       0            1
7                       3            0
8                       2            3
9                       3            1
10                      3            2
11                      4            4
12                      1            2
13                      4            0
14                      1            3
15                      2            3
16                     10            2
17                      8            0
18                      1            0
20                      6            0
21                      2            0
22                      1            0
23                      1            0
--------------------------------------

texコマンドでオプションを使用してesttab、LaTeX 出力を表示します。

于 2019-07-13T23:13:16.770 に答える