*! version 1.0.0  11May2016
program define mynlwork, eclass sortpreserve
    version 14.1

    gettoken model 0 : 0

    if "`model'" == "expm" {
    	local cname "mynlexp"
    }
    else if "`model'" == "probit" {
    	local cname "mynlprobit"
    }
    else {
    	diplay "{red}model `model' invalid"
	exit 498
    }

    syntax varlist [if] [in] [,  noCONStant ]
    marksample touse

    gettoken depvar indeps : varlist

    tempname b V N rank

    mata: MYNLWork("`depvar'", "`indeps'", "`touse'", "`constant'", ///
       "`b'", "`V'", "`N'", "`rank'", "`model'" )

    if "`constant'" == "" {
        local indeps "`indeps' _cons"
    }
    matrix colnames `b' = `indeps'
    matrix colnames `V' = `indeps'
    matrix rownames `V' = `indeps'

    ereturn post `b' `V', esample(`touse')
    ereturn scalar N       = `N'
    ereturn scalar rank    = `rank'
    ereturn local  cmd     "`cname'"

    ereturn display

end