*! version 0.1.0 2013-12-06 | vanheuvelen long

* tpr: estimate ologit

program define tpr_sim_OLMest

    qui tab $y_name if $insample
    local ntab = r(r)

    * make sure all categories are in sample
    if `ntab'!=$y_catsN { // sample does not have all categories
        scalar OLrc = -99
        scalar OLstatus = .a
    }

    * estimate model
    else {

        $qui capture ologit $y_name $x_names if $insample, iterate(200)
        scalar OLtried = 1
        scalar OLconverged = e(converged)
        scalar OLeN = e(N)
        scalar OLrc = _rc
        qui capture estimates store ologit
        scalar OLconverged = e(converged)
        if (OLrc!=0) scalar OLstatus = .c
        else if (OLconverged!=1) scalar OLstatus = .b

    }

end
exit