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

* tpr: compare OL and GL predicted probabilities
*
program define tpr_sim_probscompare

    capture matrix drop PRvec

    * list of centiles to compute
    local centilelist  "0 2 5 25 50 75 95 98 100"

    * names for centiles
    local PRnms ""
    forvalues i = $y_catmin/$y_catmax {
        foreach c in `centilelist' {
            local PRnms "`PRnms' PRdif`i'c`c'"
        }
        foreach c in `centilelist' {
            local PRnms "`PRnms' PRabsdif`i'c`c'"
        }
    }
    global PRnms `PRnms'

    * compute centiles
    forvalues icat = $y_catmin/$y_catmax {

        local centvals ""

        * difference OLM and GOLM
        qui gen PRdif`icat' = PROL`icat' - PRGL`icat'
        qui centile PRdif`icat', centile(0 2 5 25 50 75 95 98 100)
        local icent = 0
        foreach c in `centilelist' {
            local ++icent
            local cent = r(c_`icent')
            local centvals "`centvals', `cent'"
        }

        * absolute differences OLM and GOLM
        qui gen PRabsdif`icat' = abs(PRdif`icat')
        qui centile PRabsdif`icat', centile(0 2 5 25 50 75 95 98 100)
        local icent = 0
        foreach c in `centilelist' {
            local ++icent
            local cent = r(c_`icent')
            local centvals "`centvals', `cent'"
        }

        mat PRvec = (nullmat(PRvec) `centvals')

    }

    drop PRdif* PRabsdif* PROL* PRGL*

end
exit