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

* tpr: create globals used to define variables, tests
*      create matrices populated during simulations

program define tpr_sim_globals

* sampling characteristics

    global sample_planned_reps  : char _dta[sample_planned_reps]
    global sample_sizes         : char _dta[sample_sizes]
    global sample_100factor     : char _dta[sample_100factor]
    global sample_smallest      : char _dta[sample_smallest]
    global sample_maxdrawn      : char _dta[sample_maxdrawn]
    display "population data:     $popdta"
    display "sample_planned_reps: $sample_planned_reps"
    display "sample_sizes:        $sample_sizes"

* variable characteristis

    global x_names   : char _dta[x_names]
    global x_nvars   : char _dta[x_nvars]
    global y_name    : char _dta[y_name]
    global y_catmin  : char _dta[y_catmin]
    global y_catmax  : char _dta[y_catmax]
    global y_catsN   : char _dta[y_catsN]
    global ncuts     = $y_catsN - 1
    global ncutsm1   = $ncuts - 1

* wald tests after gologit2

    global WAomnibus "#1"
    forvalues i = 2/$ncuts {
        global WAomnibus "$WAomnibus=#`i'"
    }
    foreach nm of varlist $x_names {
        global WAtest_`nm' = ""
        forvalues i = 0/$ncutsm1 {
            if (`i'==$ncutsm1) global WAtest_`nm' "$WAtest_`nm' [`i']`nm'"
            else global WAtest_`nm' "$WAtest_`nm' [`i']`nm' ="
        }
        $qui di "WAtest_`nm': $WAtest_`nm'"
    }
    $qui di "WAomnibus: $WAomnibus"

* names for columns in collected results

    * OL: ologit
    local OLnms "OLtried OLstatus OLn OLconverged OLrc "
    forvalues i = 1/$x_nvars {
        local OLnms "`OLnms'OLb`i' "
        local OLnms "`OLnms'OLb`i'se "
    }
    forvalues i = 1/$ncuts {
        local OLnms "`OLnms'OLcut`i' "
        local OLnms "`OLnms'OLcut`i'se "
    }
    global OLnms "`OLnms'samplesize simiter OLaic OLbic"
    $qui di "OLnms: $OLnms"

    * GL: gologit
    local GLnms "GLtried GLstatus GLconverged GLn GLrc "
    forvalues icat = 0/$ncutsm1 {
        forvalues irhs = 1/$x_nvars {
            local GLnms "`GLnms'GLb`irhs'`icat' "
        }
        local GLnms "`GLnms'GLcut`icat' "
    }
    forvalues icat = 0/$ncutsm1 {
        forvalues irhs = 1/$x_nvars {
            local GLnms "`GLnms'GLb`irhs'`icat'se "
        }
        local GLnms "`GLnms'GLcut`icat'se "
    }
    global GLnms "`GLnms' GLaic GLbic BICdif AICdif"
    $qui di "GLnms: $GLnms"

    * omnibus BR brant, WA gologit wald, LR gologit lr
    global BRnms "BRtried BRstatus BRdf BRchi BRprob BRrc"
    global WAnms "WAtried WAstatus WAdf WAchi WAprob WArc"
    global LRnms "LRtried LRstatus LRdf LRchi LRprob LRrc"
    $qui di "BRnms: $BRnms"
    $qui di "WAnms: $WAnms"
    $qui di "LRnms: $LRnms"

    * individual coefs BR and WA
    local WAtestallnms ""
    local BRtestallnms ""
    foreach nm in $x_names {
        local WAtestvar_`nm' "WA`nm'status WA`nm'df WA`nm'chi WA`nm'prob WA`nm'rc"
        local WAtestallnms   "`WAtestallnms'`WAtestvar_`nm'' "
        global WAtestvar_`nm' `WAtestvar_`nm''
        local BRtestvar_`nm' "BR`nm'status BR`nm'df BR`nm'chi BR`nm'prob BR`nm'rc"
        local BRtestallnms   "`BRtestallnms'`BRtestvar_`nm'' "
        global BRtestvar_`nm' `BRtestvar_`nm''
        $qui di "WAtestvar_`nm': $WAtestvar_`nm'"
        $qui di "BRtestvar_`nm': $BRtestvar_`nm'"
    }
    global WAtestallnms "`WAtestallnms'"
    global BRtestallnms "`BRtestallnms'"
    $qui di "WAtestallnms: $WAtestallnms"
    $qui di "BRtestallnms: $BRtestallnms"

    global OPnms "SCchi SCprob SCdf WGchi WGprob WGdf" // oparallel results

* matrices used to hold results

    matrix OLnullvec    = J(1,($x_nvars+$ncuts), .n)
    matrix GLnullvec    = J(1,(($x_nvars + 1)*$ncuts),.n)
    matrix PRnullvec    = J(1,($y_catsN*27),.n)
    matrix null4vec     = J(1,4,.n)
    matrix null5vec     = J(1,5,.n)
    matrix OLicnullvec  = J(1,2,.n)
    matrix GLicnullvec  = J(1,4,.n)
    matrix OPnullvec    = J(1,6,.n)

end