*! beta version 0.1.0 2014-09-12 | scott long

//  compute statistics from nlcom returns

program define _rm_nlcom_stats, rclass

    tempname estval seval levelval levelpval cifactorval zval pval lbval ubval

    tempname rb rv
    mat `rb' = r(b)
    mat `rv' = r(V)
    scalar `estval'     = `rb'[1,1]
    scalar `seval'      = sqrt(`rv'[1,1])
    scalar `zval'       = `estval'/`seval' // zvalue
    scalar `pval'       = 2*(1-normal(abs(`zval'))) // pvalue 2 tailed
    scalar `levelval'   = $S_level // level for CI
    scalar `levelpval'  = ( 1 - (`levelval'/100) )/2 // pval for ci
    scalar `cifactorval' =  abs(invnormal(`levelpval')) // +- multiplier for ci
    scalar `lbval'      = `estval' - (`cifactorval'*`seval') // lb
    scalar `ubval'      = `estval' + (`cifactorval'*`seval') // ub

    return scalar est   = `estval'
    return scalar se    = `seval'
    return scalar z     = `zval'
    return scalar p     = `pval'
    return scalar lb    = `lbval'
    return scalar ub    = `ubval'
    return scalar level = `levelval'

end
exit