Dominik Vogel
Dominik Vogel

Reputation: 316

Number of groups in esttab (after xtmixed)

i'd like to add the number of groups to a esttab output after fitting a multilevel model in Stata (xtmixed). I found this post and understand that the number of groups is stores in the matrix e(N_g). However, I do not understand, how to use the value in this matrix and add it to the output. I tried estadd but did not manage to get it work. I also did not find something about using a single cell of a matrix in an output in the estout manual.

Any ideas on how to add the number of gorups to a esttab output? Or maybe experiences with adding single values from a matrix?

Thx!!!

P.S. This is the output of matrix list e(N_g)

symmetric e(N_g)[1,1]
    c1
r1  117

Upvotes: 4

Views: 2508

Answers (2)

L. Francis Cong
L. Francis Cong

Reputation: 359

Actually, esttab, stats(N_g, labels("N")) is sufficient. estout can recognize N_g.

Upvotes: 1

Eric HB
Eric HB

Reputation: 887

Estadd is the way to go, here is an example:

clear all
webuse pig

// model
eststo: xtmixed weight week || id:, vce(robust)

// estadd portion - pull the single element of the matrix into a local and estadd it
matrix N_g = e(N_g)
local groups = N_g[1,1]
estadd local groups `groups'

// add groups in the stats option and it will appear at the bottom along
// with the number of observations in this case
esttab ., stats(N groups)

Upvotes: 5

Related Questions