Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Estout and number of observations


From   "Ben Jann" <[email protected]>
To   [email protected]
Subject   Re: st: Estout and number of observations
Date   Mon, 26 Nov 2007 16:32:21 +0100

If you want extended information on the refcat in the table, then I
suggest adding a parameter for the refcat in the model. In some
situations and with some commands this can be done simply by including
the refcat variable in the command. Example:

sysuse auto, clear
tabulate rep, generate(_Irep)
regress price weight _Irep*
capture matrix drop num
foreach cat of varlist _Irep* {
   count if `cat'==1 & e(sample)
   matrix num = nullmat(num), r(N)
   local collab "`collab'`cat' "
}
matrix colname num = `collab'
estadd matrix num
estout, cell("num b") style(smcl)

--------------------------------------
                        .
                      num            b
--------------------------------------
weight                        2.440292
_Irep1                  2            0
_Irep2                  8     783.9009
_Irep3                 30     1379.115
_Irep4                 18     2068.267
_Irep5                 11     3245.272
_cons                        -3000.405
--------------------------------------

In other cases you would have to add the parameter afterwards by
modifying e(b) and e(V) and reposting the results using -erepost- (use
the modified results for tabulation only). Example:

sysuse auto, clear
tabulate rep, generate(_Irep)
regress price weight _Irep2-_Irep5
mat ref = 0
mat coln ref = _Irep1
mat rown ref = _Irep1
mat b = e(b)
mat V = e(V)
mat b = b,ref
mat V = (V,(ref \ J(rowsof(V)-1,1,0))) \ (ref,J(1,colsof(V),0))
erepost b=b V=V
capture matrix drop num
foreach cat of varlist _Irep* {
   count if `cat'==1 & e(sample)
   matrix num = nullmat(num), r(N)
   local collab "`collab'`cat' "
}
matrix colname num = `collab'
estadd matrix num
estout, cell("num b") style(smcl) order(weight _Irep1)

--------------------------------------
                        .
                      num            b
--------------------------------------
weight                        2.440292
_Irep1                  2            0
_Irep2                  8     783.9009
_Irep3                 30     1379.115
_Irep4                 18     2068.267
_Irep5                 11     3245.272
_cons                        -3000.405
--------------------------------------

If you want to get rid of the zero,  you can type

estout, cell("num b(drop(_Irep1))") style(smcl) order(weight _Irep1)

--------------------------------------
                        .
                      num            b
--------------------------------------
weight                        2.440292
_Irep1                  2
_Irep2                  8     783.9009
_Irep3                 30     1379.115
_Irep4                 18     2068.267
_Irep5                 11     3245.272
_cons                        -3000.405
--------------------------------------

If you want to substitute the 0 with some text, I suggest the following:

sysuse auto, clear
tabulate rep, generate(_Irep)
regress price weight _Irep2-_Irep5
mat ref = -999
mat coln ref = _Irep1
mat rown ref = _Irep1
mat b = e(b)
mat V = e(V)
mat b = b,ref
mat ref[1,1] = 0
mat V = (V,(ref \ J(rowsof(V)-1,1,0))) \ (ref,J(1,colsof(V),0))
erepost b=b V=V
capture matrix drop num
foreach cat of varlist _Irep* {
   count if `cat'==1 & e(sample)
   matrix num = nullmat(num), r(N)
   local collab "`collab'`cat' "
}
matrix colname num = `collab'
estadd matrix num
estout, cell("num b") style(smcl) order(weight _Irep1) substitute(-999 "ref.")

--------------------------------------
                        .
                      num            b
--------------------------------------
weight                        2.440292
_Irep1                  2         ref.
_Irep2                  8     783.9009
_Irep3                 30     1379.115
_Irep4                 18     2068.267
_Irep5                 11     3245.272
_cons                        -3000.405
--------------------------------------


ben

On Nov 26, 2007 11:12 AM, raoul reulen <[email protected]> wrote:
> Brilliant! Thanks very much Ben.  I use the refcat option in estout,
> but because the reference category does not appear in the regression
> model it doesn't give me the number of observations for this category.
> How can I get the number of observations for the reference category as
> well? I have been trying to figure it out but couldn't do it. I would
> be grateful for any suggestions.
>
>
> On 21/11/2007, Ben Jann <[email protected]> wrote:
> > This requires some programming. Here's an example;
> >
> > sysuse auto, clear
> > xi: reg price weight i.rep
> > capture matrix drop num
> > foreach cat of varlist _Irep* {
> >    count if `cat'==1 & e(sample)
> >    matrix num = nullmat(num), r(N)
> >    local collab "`collab'`cat' "
> > }
> > matrix colname num = `collab'
> > estadd matrix num
> > estout, cell("num b") style(smcl)
> >
> > which yields
> >
> > --------------------------------------
> >                        .
> >                      num            b
> > --------------------------------------
> > weight                        2.440292
> > _Irep78_2               8     783.9009
> > _Irep78_3              30     1379.115
> > _Irep78_4              18     2068.267
> > _Irep78_5              11     3245.272
> > _cons                        -3000.405
> > --------------------------------------
> >
> >
> > ben
> >
> > On Nov 20, 2007 6:08 PM, Raoul Reulen <[email protected]> wrote:
> > > I am running a logistic regression model and save the estimates to estout. Now for a specific factor in the model I would also like to add the number of observations for each level of the factor.
> > >
> > >
> > >
> > > So for example;
> > >
> > >
> > >
> > > xi: logit dead i.diagnosis
> > >
> > > .estout . using "output/table2.xls",  cells("b(fmt(%9.1f)) ci(par( ( , ) ))") eform  replace
> > >
> > >
> > >
> > > Whereby::
> > >
> > > dead (yes=1, no=0)
> > >
> > > Diagnosis  (leukaemia=1, Hodgkins=2, retinoblastoma=3 etc)
> > >
> > >
> > >
> > > So this gives the estimates and confidence intervals for the factor diagnosis. How do I add the number of observations for each level of the factor diagnosis? So for example:
> > >
> > >
> > >
> > > Diagnosis          Number            estimate            95%CI
> > >
> > > Leukaemia        450                  3.0                   (2.0,5.0)
> > >
> > > Hodgkins          230                  4.9                   (3.0,8.4)
> > >
> > >
> > >
> > > How do I get a column with the number of observations such as in this example if possible?
> > >
> > >
> > >
> > > Thanks,
> > >
> > >
> > >
> > > Raoul
> > >
> > >
> > > Raoul Reulen
> > > Cancer Research UK Graduate Training Fellow
> > >
> > >
> > > *
> > > *   For searches and help try:
> > > *   http://www.stata.com/support/faqs/res/findit.html
> > > *   http://www.stata.com/support/statalist/faq
> > > *   http://www.ats.ucla.edu/stat/stata/
> > >
> > *
> > *   For searches and help try:
> > *   http://www.stata.com/support/faqs/res/findit.html
> > *   http://www.stata.com/support/statalist/faq
> > *   http://www.ats.ucla.edu/stat/stata/
> >
>
>
> --
> -------------------------------------------------------
> Raoul C. Reulen
> Cancer Research UK Training Fellow
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index