/*
  mprobit

*!  VERSION 1.1.9  23aug2010

  keyword:  eclass

*/

VERSION 12.0
INCLUDE _std_large
DEFINE _dlght 330
INCLUDE header

HELP hlp1, view("help mprobit")
RESET res1

SCRIPT PREINIT
BEGIN
	program parseMessage
	script se_createAsSvyJknifeBstrapML
	program svy_check_title
END

PROGRAM parseMessage
BEGIN
	if __MESSAGE.contains("__MI__") {
		call script se_setMI_on
	}
END

SCRIPT POSTINIT
BEGIN
	program check_bytab
	program se_setFinalInitState
END

PROGRAM check_bytab
BEGIN
	if ! __MESSAGE.contains("__MI__") {
		call script sub_set_by_on
	}
END

SCRIPT svy_is_on
BEGIN
	script max_setDefaultNoLog
END
SCRIPT svy_is_off
BEGIN
	script max_setDefaultLog
END
PROGRAM svy_check_title
BEGIN
	if __MESSAGE.contains("-svy-") {
		call settitle "svy: mprobit - Multinomial probit regression for survey data"
	}
END

DIALOG main, tabtitle("Model")						///
	/// **** has svy title ****					///
	title("mprobit -  Multinomial probit regression")
BEGIN
  TEXT tx_dv 		_lft	_top	_vnwd	.,			///
	label("Dependent variable:")
  VARNAME vn_dv		@ 	_ss	@	.,			///
	label("Dependent variable")

  TEXT tx_iv		_vlx	_top	160	.,			///
	label("Independent variables:")
  VARLIST vl_iv		@	_ss	_vlwd	.,			///
	fv								///
	allowcat							///
	label("Independent variables")

  CHECKBOX ck_nocons @         _ms       @         .,			///
	label("Suppress constant terms")				///
	option(noconstant)

  GROUPBOX gb_output _lft      _ls       _iwd      _ht14,		///
	label("Options")

  CHECKBOX ck_base   _ilft     _ls       _ckwd     .,			///
	onclickon(main.en_base.enable)					///
	onclickoff(main.en_base.disable)
  EDIT     en_base   _cksep    @         _en14wd   .,			///
	label("Base outcome") 						///
	option(baseoutcome)
  TEXT     tx_base   _en14sep  @         _cken7r2b .,			///
	label("Base outcome")

  CHECKBOX ck_probitparam	_ilft	_ls	_ibwd	.,		///
  	option(probitparam)						///
  	label("Use the probit variance parameterization")

  DEFINE _x _ilft
  DEFINE _y _ms
  DEFINE _cx _ilw80
  DEFINE _bux _islw80
  INCLUDE _constraints

  DEFINE _x _ilft
  DEFINE _xw _ibwd
  INCLUDE _ck_collinear
END

INCLUDE _constraints_sc 
INCLUDE sub_by_ifin_over_subpop
INCLUDE weights_fpi
INCLUDE se

SCRIPT rpt_POSTINIT
BEGIN
	create STRING rpt_bu_fmtcoefResults
	program rpt_bu_fmtcoef_ckResults
END

DIALOG rpt, tabtitle("Reporting")
BEGIN
  DEFINE _x _lft
  DEFINE _cx _spr
  DEFINE _y _top
  INCLUDE _sp_level

  DEFINE _x _lft
  DEFINE _y _ls
  DEFINE _cx _iwd
  INCLUDE _nocnsreport

  DEFINE _x _lft
  DEFINE _y _ms
  DEFINE _cx _iwd
  INCLUDE _noomitted

  DEFINE _x _lft
  DEFINE _y _ms
  DEFINE _cx _iwd
  INCLUDE _vsquish

  DEFINE _x _lft
  DEFINE _y _ms
  DEFINE _cx _iwd
  INCLUDE _factor_vars_reporting

  DEFINE _x _lft
  DEFINE _y _xxxls
  INCLUDE _bu_coef_table_reporting
END

INCLUDE fmt_coef_table_reporting_pr

PROGRAM rpt_output
BEGIN
	optionarg /hidedefault rpt.sp_level
	INCLUDE _nocnsreport_pr
	INCLUDE _noomitted_pr
	INCLUDE _vsquish_pr
	INCLUDE _factor_vars_reporting_pr
	put " " rpt_bu_fmtcoefResults
END

DIALOG int, tabtitle("Integration")
BEGIN
  SPINNER  sp_intpoints		_lft	_top	_spwd	.,		///
  	option(intpoints) min(1) default(15) max(100)
  TEXT     tx_intpoints		_spsep	@	200	.,		///
  	label("Number of quadrature points")
END

PROGRAM int_output
BEGIN
	optionarg /hidedefault int.sp_intpoints
END

INCLUDE max_ml

PROGRAM command
BEGIN
	put /program by_output " "
	put /program se_prefix_output " "
	put "mprobit "
	varlist main.vn_dv [main.vl_iv]
	if !main.vl_iv & main.ck_nocons {
	  stopbox stop `""Suppress constant term" is selected without independent variables."'
	}
	put " " /program ifin_output
	put " " /program weights_output
	beginoptions
		option main.ck_nocons
		if main.ck_base {
			optionarg main.en_base
		}
		option main.ck_probitparam
		INCLUDE _constraints_main_pr
		option main.ck_collinear
		put " " /program se_output
		put " " /program rpt_output
		put " " /program int_output
		put " " /program max_output
	endoptions
END
