# st: hit rate after logit model

 From Dirk Nachbar To statalist Subject st: hit rate after logit model Date 02 Jun 2006 16:18:05 +0100

All

here is a program (the last for this week I promise) which is supposed to run after various choice models. It should calculate the hit rate of correct predictions. Two things create problems: the mean hit rate is not shown and the -foreach- loop doesn't seem to work. Maybe someone would like to take a closer look.

clear

set obs 100

gen x=invnorm(uniform())

gen e=invnorm(uniform())

gen y=round(2*exp(1+x+e)/(1+exp(1+x+e)),1)

ologit y x

/*

Program to run after most Discrete Choice Models

it reports the hit rate of correct predictions

*/

capture program drop postdcm

program define postdcm

version 8.2

syntax [if] [in] [, threshold(real 0.5)]

if `threshold'<0 | `threshold'>1 {

di as error "threshold has to be between 0 and 1"

exit 198

}

if "`e(cmd)'"=="" {

di as error "no DCM estimations found"

exit 198

}

if "`e(cmd)'"=="logit" | "`e(cmd)'"=="probit" | "`e(cmd)'"=="xtlogit" | "`e(cmd)'"=="xtprobit" {

tempvar pred pred2

qui predict pred

gen pred2=(pred>=`threshold')

gen hit=(`e(depvar)'==pred2)

sum hit

tab `e(depvar)' pred2, freq nocol

di in green "the mean hit rate is `r(mean)'"

}

if "`e(cmd)'"=="ologit" | "`e(cmd)'"=="oprobit" | "`e(cmd)'"=="mlogit" | "`e(cmd)'"=="mprobit" {

qui sum `e(depvar)'

gen pred=`r(min)'

foreach i=`r(min)'/`r(max)' {

tempvar pred`i'

qui predict pred`i', outcome(`i')

if `i'==`r(min)' {

gen pred=`i'

local max=pred`i'

}

else if pred`i'>`max' {

replace pred=`i'

local max=pred`i'

}

}

gen hit=(`e(depvar)'==pred)

qui sum hit

tab `e(depvar)' pred, freq nocol

di in green "the mean hit rate is `r(mean)'"

}

end

postdcm

Dirk Nachbar

Assistant Economist

Pensim2

Department for Work and Pensions