Statalist


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

Re: st: Customizing display of response variable's name in -ml display-


From   [email protected] (Jeff Pitblado, StataCorp LP)
To   [email protected]
Subject   Re: st: Customizing display of response variable's name in -ml display-
Date   Wed, 07 May 2008 13:36:41 -0500

Joseph Coveney <[email protected]> is using a temporary variable with
-ml- in his ado-file estimation command but wants to show something other than
the tempvar's name in the output:

> Is there a way to provide an informative variable name in -ml display- when
> the ado-file has to make use of a temporary variable for the actual
> estimation?
> 
> For example, after convergence using the ado-file pair below,
> -ml display- shows the response variable as __000000 in the regression
> table.  I examined the documentation for -ml- and looked through W. Gould,
> J. Pitblado & W. Sribney, _Maximum Likelihood Estimation with Stata_ Third
> Edition. (College Station, Texas: Stata Press, 2006), but couldn't find any
> way to change the display to show the original dependent variable's name.

Joseph can use 'ereturn local' to change the contents of 'e(depvar)' after
-ml- fits the model.  For example, Joseph can add the following line to
-firthlogit.ado- to make -e(depvar)- contain the variable name supplied by the
user:

	ereturn local depvar `response'

I added the above line in Joseph's Stata code, which appears after my
signature.

--Jeff
[email protected]

> ---------------Main ado-file (-firthlogit.ado-)-------------
> 
> *! firthlogit.ado Version 0.05 JRC 2008-02-11
> program define firthlogit, eclass
>     version 10
>     syntax varlist(numeric) [if] [in] [fweight] [, nolog]
>     tempvar tmpvar0
>     tempname tmpnam0
> 
>     marksample touse
> 
> // Initial values
>     gettoken response predictors : varlist
>     generate byte `tmpvar0' = (`response' != 0) if `touse'
>     summarize `tmpvar0' `weight' `exp', meanonly
>     if inlist(r(mean), 0, 1) {
>         display in smcl as text "outcome does not vary; remember:"
>         display in smcl as text ///
> "                                  0 = negative outcome,"
>         display in smcl as text ///
> "        all other nonmissing values = positive outcome"
>         error 99
>     }
>     scalar define `tmpnam0' = logit(r(mean))
> 
>     local k : word count `predictors'
>     if (`k') matrix define `tmpnam0' = (J(1, `k', 0), `tmpnam0')
>     else matrix define `tmpnam0' = (`tmpnam0')
> 
>     global firthlogitpredictors `predictors'
> 
>     ml model d0 _firthlogit ///
> (xb: `tmpvar0' = `predictors') if `touse' `weight' `exp', ///
>       missing init(`tmpnam0', copy) maximize ///
> crittype("penalized log likelihood") `log'
>
>     ereturn local depvar `response'	// <- NEW LINE
> end
> 
> ------------------------------------------------------------
> 
> --------estimation ado-file (-_firthlogit.ado-)-------------
> 
> program define _firthlogit
>     version 10
>     args todo b lnL
>     tempvar xb mu se
>     tempname I
> 
>     assert !`todo'
>     mleval `xb' = `b', eq(1)
>     quietly {
>         generate double `mu' = invlogit( `xb') if $ML_y1 == 1
>         replace         `mu' = invlogit(-`xb') if $ML_y1 == 0
>         mlsum `lnL' = ln(`mu')
> 
>         generate double `se' = sqrt(`mu' * (1 - `mu'))
>         local mataccumlist
>         foreach var of global firthlogitpredictors {
>             tempvar `var'
>             generate double ``var'' = `var' * `se'
>             local mataccumlist `mataccumlist' ``var''
>         }
>         matrix accum `I' = `mataccumlist' `se', noconstant
>         scalar define `lnL' = `lnL' + ln(det(`I')) / 2
> 
>     }
> end
> 
> ------------------------------------------------------------ 
> 
> 
> *
> *   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