I found some issues with Stata's leastlikely
command, so I fixed it up a bit. If you're getting issues with missing brackets, or failed to generate "Prob" or the error option outcome() not allowed
then this will probably help. It's called leastlikely2
, but you can rename it.
I also found that to give it a variable to put the probabilities into, you need to give it a previously generated variable.
gen pr = .
leastlikely2, generate(pr)
*! version 1.0.1 Jeremy Freese 17 June 2002 (SJ2-3: st0022) * version 1.0.1-1 by Ryan Castle 29 March 2006 capture program drop leastlikely2 program define leastlikely2 syntax [varlist(default=none)] [if] [in] [, n(integer 5) generate(varname) *] if "`e(cmd)'"=="clogit" | "`e(cmd)'"=="nlogit" | "`e(cmd)'"=="xtlogit" | /* */ "`e(cmd)'"=="blogit" | "`e(cmd)'"=="bprobit" | "`e(cmd)'"=="glogit" | /* */ "`e(cmd)'"=="gprobit" { di _n as err "leastlikely not intended for use after `e(cmd)'" exit 198 } local erase "no" tempname values prob touse local depvar = "`e(depvar)'" local depvarlabel : value label `depvar' if "`generate'"=="" { local generate "Prob" local erase "yes" } noisily { gen `touse' = e(sample) `if' `in' gen `prob' = . tabulate `depvar' if e(sample)==1, matrow(`values') local temp : rownames `values' local numcats : word count `temp' forvalues i = 1(1)`numcats' { local value`i' = `values'[`i', 1] } local isbin "no" if `numcats'==2 & `value1'==0 & `value2'==1 { local isbin "yes" } di "isbin=`isbin' numcats=`numcats' value1=`value1' value2=`value2'" if "`isbin'" == "yes" { tempname temp predict `temp', p replace `prob' = `temp' if `depvar'==1 & `touse'==1 replace `prob' = (1-`temp') if `depvar'==0 & `touse'==1 } if "`isbin'" == "no" { forvalues i = 1(1)`numcats' { tempname temp predict `temp', outcome(`value`i'') replace `prob' = `temp' if `depvar'==`value`i'' & `touse'==1 } } replace `generate' = `prob' } forvalues i = 1(1)`numcats' { local vallabel "" if "`depvarlabel'"!="" { local vallabel : label `depvarlabel' `value`i'' if "`vallabel'"!="" { local vallabel = "(`vallabel')" } } di _n as txt "Outcome: " as res `value`i'' " `vallabel'" tempname temp quietly egen `temp' = rank(`generate') if `depvar'==`value`i'' & `touse'==1, track list `generate' `varlist' if `temp'< =`n' , `options' } if "`erase'"=="yes" { drop `generate' } end
Comments
No comments yet.
Leave a comment