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

* tpr: gologit2 post-estimation

program define tpr_sim_GOLMpostest

*   gologit2 results

    scalar GLstatus = 1
    matrix GLse = e(gamma_se)
    matrix GLbeta = e(b)

*   ic statistics

    $qui estat ic
    scalar GLaic = el(r(S),1,5)
    scalar GLbic = el(r(S),1,6)

    scalar BICdif = OLbic - GLbic
    scalar AICdif = OLaic - GLaic

*   collect results

    matrix GLvec = GLstatus, ///
        GLtried, e(converged), e(N), GLrc, e(b), e(gamma_se) ///
        , GLaic, GLbic, BICdif, AICdif

*   omnibus wald

    $qui capture test [$WAomnibus]
    scalar WAtried = 1
    scalar WArc = _rc
    $qui di "  + WA rc " WArc
    if WArc==0 {
        scalar WAstatus = 1
        matrix WAvec = WAtried, WAstatus,r(df),r(chi2),r(p),WArc
    }
    else matrix WAvec = WAtried, .h, ., ., ., WArc

*   individual wald tests

    foreach nm of varlist $x_names {
        $qui capture test $WAtest_`nm'
        scalar WAvarrc = _rc
        if WAvarrc == 0 {
            matrix WA`nm'vec = 1, r(df), r(chi2), r(p), WAvarrc
        }
        else matrix WA`nm'vec = .h, ., ., ., WAvarrc
    }

*   omnibus LR test

    $qui capture lrtest . ologit, stats force
    scalar LRtried = 1
    scalar LRrc = _rc
    $qui di "  + LR rc " LRrc
    if LRrc==0 {
        scalar LRstatus = 1
        mat LRvec = LRtried, LRstatus, r(df), r(chi2), r(p), LRrc
    }
    else matrix LRvec = LRtried, i., ., ., ., LRrc

*   predicted prob

    local prnms ""
    forvalues i = $y_catmin/$y_catmax {
        local prnms "`prnms' PRGL`i'"
    }
    qui predict `prnms' if $insample

    * check neg prob
	foreach var of varlist `prnms' {
		quietly count if `var' < 0 & $insample
		if (r(N)!=0) scalar GLstatus = .n
	}

end
exit