Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to print numbers of levels in melogit models using esttab?

    Hello dear statalists:

    I am using estout from SSC in Stata 17.0 on Windows 10. My goal is to fit a multi-level model using melogit and print the estimates using esttab. I want the table to show numbers of distinct grouping levels (parties and countries), so I wrote the following command:

    Code:
    melogit Y x1 x2 x3 || country: || party:
    est store model1 
    
    esttab model1 label nodep style(tex) nomtitles ///
    cells(b(star fmt(a1)) se(fmt(a1) par)) replace star(* 0.10 ** 0.05 *** 0.01) stats(N N_g)
    However, no value was shown on the N_g row.

    According to the melogit`s documentation, it stores N_g as a matrix. But the esttab manual indicates that stats() option only accepts scalars. So I modified the code as follows:

    Code:
    melogit Y x1 x2 x3 || country: || party:
    est store model1 
    matrix N_g = e(N_g) 
    estadd scalar N_party = N_g[1,2]
    estadd scalar N_country = N_g[1,1]
    
    esttab model1 label nodep style(tex) nomtitles cells(b(star fmt(a1)) se(fmt(a1) par)) ///
    replace star(* 0.10 ** 0.05 *** 0.01) stats(N N_party N_country)
    Now the table has two rows called N_party and N_country, and they are displaying the correct # of levels.

    My questions are:
    1. Is there a more elegant way to do this? Since my code would be applied to many different models, adding a few lines after each model fitting could make the project quite messy.
    2. Is it possible to store all N_g values in a separate variables like a varlist, and then use them as input to stats()? Or does esttab only accept values added with estadd?
    Your advices would be greatly appreciated. Many thanks for your time!

Working...
X