/*
  rologit

*!  VERSION 1.1.9  23aug2010

  keyword:  eclass

*/

VERSION 12.0

INCLUDE _std_large
INCLUDE _ht320
INCLUDE header

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

DIALOG main, label("rologit - Rank-ordered logistic regression") tabtitle("Model")
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")

  TEXT     tx_group  _lft      _ms       _iwd      .,			/*
		*/ label("Group variable:")				/*
		*/
  VARNAME  vn_group  _lft      _ss       _vnwd     .,			/*
		*/ label("Group variable")				/*
		*/ option("group")					/*
		*/

  GROUPBOX gb_option _lft      _ls       _iwd      _ht17h,		/*
  		*/ label("Options")
  TEXT     tx_offset _ilft     _ss       _inwd     .,			/*
		*/ label("Offset variable:")				/*
		*/
DEFINE y @y
  VARNAME  vn_offset @         _ss       _vnwd     .,			/*
		*/ label("Offset variable")				/*
		*/ option("offset")					/*
		*/

  TEXT     tx_inc    _lft2     y          _cwd2     .,			/*
		*/ label("Code for unranked alternatives:")		/*
		*/
  EDIT     en_inc    @         _ss       _en7wd    ., numonly		/*
		*/ label("Code for unranked alternatives")		/*
		*/ option("incomplete")					/*
		*/ default("0")						/*
		*/
  TEXT     tx_inc2   _en7sep   @         _en7r2b   .,			/*
		*/ label("(default: 0)")				/*
		*/

  CHECKBOX ck_rev    _ilft     _ls       _cwd2     .,			/*
		*/ label("Reverse the preference order")		/*
		*/ option("reverse")					/*
		*/
  CHECKBOX ck_notest @         _ms       _ibwd     .,			/*
		*/ label("Keep RHS variables that do not vary within group") /*
		*/ option("notestrhs")					/*
		*/

  GROUPBOX gb_tied   _ilft     _ls       _ibwd     _ht4,		/*
		*/ label("Method to handle ties")			/*
		*/
  RADIO    rb_exactm _indent   _ss       _cwd3     .,			/*
		*/ label("Exact marginal likelihood")			/*
		*/ first						/*
		*/ option("ties(exactm)")				/*
		*/ onclickon(script exactm_on)
  DEFINE y @y
  RADIO    rb_efron  @         _ss       @         .,			/*
		*/ label("Efron")					/*
		*/ option("ties(efron)")				/*
		*/ onclickon(script efron_on)
  RADIO    rb_breslow _lft2    y         @         .,			/*
		*/ label("Breslow")					/*
		*/ option("ties(breslow)")				/*
		*/ onclickon(script breslow_on)
  RADIO    rb_none   @         _ss       @         .,			/*
		*/ label("None")					/*
		*/ option("ties(none)")					/*
		*/ onclickon(script none_on) last
END

SCRIPT exactm_on
BEGIN
	program enable_weights
	script se_setRobust_off
END

SCRIPT none_on
BEGIN
	program enable_weights
	script se_setClRobust_on
END

SCRIPT breslow_on
BEGIN
	program enable_weights
	script se_setClRobust_on
END

SCRIPT efron_on
BEGIN
	program disable_weights
	script se_setClRobust_on
END


INCLUDE byifin
INCLUDE weights_fpi
INCLUDE se

SCRIPT PREINIT
BEGIN
	script se_createAsInternalML
END

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 _spr2b
  DEFINE _y 20
  INCLUDE _sp_level

  DEFINE _x _lft
  DEFINE _y _ls
  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

INCLUDE max_internal

PROGRAM command
BEGIN
	INCLUDE _by_pr
	put "rologit "
	varlist main.vn_dv
	varlist main.vl_iv
	INCLUDE _weights_pr
	INCLUDE _ifin_pr
	beginoptions
		require main.vn_group
		optionarg main.vn_group
		optionarg main.vn_offset
		option main.ck_rev
		option main.ck_notest
		optionarg /hidedefault main.en_inc
		option radio(main rb_exactm rb_breslow rb_efron rb_none)
		optionarg /hidedefault rpt.sp_level
		INCLUDE _noomitted_pr
		INCLUDE _vsquish_pr
		INCLUDE _factor_vars_reporting_pr
		put " " rpt_bu_fmtcoefResults
		put " " /program se_output
		put " " /program max_output
	endoptions
END
