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

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

From   "Joseph Coveney" <>
To   "Statalist" <>
Subject   st: Customizing display of response variable's name in -ml display-
Date   Wed, 7 May 2008 09:36:29 +0900

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

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 Coveney

---------------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'


--------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



* For searches and help try:

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