/*
  permute

*! VERSION 2.1.5  16may2011

*/

VERSION 12.0

INCLUDE _std_large
DEFINE _dlght 410
INCLUDE header

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

DIALOG main, label("permute - Monte Carlo permutation tests") tabtitle("Main")
BEGIN
  TEXT     tx_pervar _lft      _top      _cwd1     .,			/*
		*/ label("Permutation variable:")			/*
		*/
  VARNAME  vn_pervar @         _ss       _vnwd     .,			/*
		*/ label("Permutation variable")			/*
		*/

  SPINNER  sp_reps   _lft2     @         _spwd     .,			/*
		*/ label("Replications")				/*
		*/ min(1)						/*
		*/ max(1000000)						/*
		*/ default(100)						/*
		*/ option("reps")					/*
		*/
  TEXT     tx_reps   _spsep    @         _spr2     .,			/*
		*/ label("Replications")				/*
		*/

  DEFINE _y _ls
  INCLUDE _cmd_exp_list

  GROUPBOX gb_event  _lft       _xls     _iwd     _ht6,			/*
		*/ label("Direction of comparisons")			/*
		*/
  DEFINE _y @y
  RADIO    rb_two    _indent    _ss      _cwd3     .,			/*
		*/ first						/*
		*/ label("Two sided")					/*
		*/ option("NONE")					/*
		*/
  RADIO    rb_left   @          _ss      @         .,			/*
		*/ label("Left tail")					/*
		*/ option("left")					/*
		*/
  RADIO    rb_right  @          _ss      @         .,			/*
		*/ last							/*
		*/ label("Right tail")					/*
		*/ option("right")					/*
		*/
END

DIALOG opt, tabtitle("Options")
BEGIN
  TEXT tx_strata     _lft       _top      _iwd     .,			/*
		*/ label("Permute within strata:")
  VARLIST  vl_strata @   _ss       _cwd3     .,				/*
		*/ label("Strata variable(s)")				/*
		*/ option("strata")					/*
		*/
  DEFINE _y _xls
  INCLUDE _saving
END

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

  CHECKBOX ck_noheader _lft    _ls       _cwd1     .,			/*
		*/ label("Suppress the table header")			/*
		*/ clickon(program check_header)			/*
		*/ clickoff(program check_header)			/*
		*/ option("noheader")					/*
		*/
  CHECKBOX ck_nolegend  @      _ms       @         .,			/*
		*/ label("Suppress the table legend")			/*
		*/ clickon(program check_legend)			/*
		*/ clickoff(program check_legend)			/*
		*/ option("nolegend")					/*
		*/
  CHECKBOX ck_verbose @        _ms       @         .,			/*
		*/ label("Display the full table legend")		/*
		*/ option("verbose")					/*
		*/
  CHECKBOX ck_nodrop  @        _ms       @         .,			/*
		*/ label("Do not drop observations")			/*
		*/ option("nodrop")					/*
		*/

  TEXT     tx_title	_lft	_ls	_iwd	.,			///
	label("Title:")
  EDIT     ed_title	@	_ss	@	.,			///
	label("Title")							///
	option(title)

  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 250
  DEFINE _cx 240
  DEFINE _y _top
  DEFINE _cy _ht6
  INCLUDE _output_reps
END

PROGRAM check_legend
BEGIN
	if opt.ck_nolegend {
		call gaction opt.ck_verbose.disable
	}
	if !opt.ck_nolegend {
		call gaction opt.ck_verbose.enable
	}
END

PROGRAM check_header
BEGIN
	if opt.ck_noheader {
		call gaction opt.ck_nolegend.disable
		call gaction opt.ck_verbose.disable
	}
	if !opt.ck_noheader {
		call gaction opt.ck_nolegend.enable
		call program check_legend
	}
END


INCLUDE _saving_sc

DIALOG adv, tabtitle("Advanced")
BEGIN
  EDIT     en_eps    _lft      _top      _en7wd    .,			/*
		*/ label("Numeric tolerance")				/*
		*/ numonly						/*
		*/ option("eps")					/*
		*/
  TEXT     tx_eps    _en7sep   @         _en7r     .,			/*
		*/ label("Numeric tolerance (rarely needed)")		/*
		*/
  CHECKBOX ck_nowarn _lft      _ls       _iwd      .,			/*
		*/ label("Do not warn when e(sample) is not set")	/*
		*/ option("nowarn")					/*
		*/
  CHECKBOX ck_force  @         _ms       _iwd      .,			/*
		*/ label("Do not check for weights or svy commands")	/*
		*/ option("force")					/*
		*/

  TEXT     tx_reject @         _ls       @         .,			/*
		*/ label("Identify invalid results:")			/*
		*/
  EDIT     ed_reject @         _ss       @         .,			/*
		*/ label("Identify invalid results")			/*
		*/ option("reject")					/*
		*/

  TEXT     tx_seed   @         _ls       @         .,			/*
		*/ label("Random number seed:")				/*
		*/
  EDIT     ed_seed   @         _ss       _en14wd   .,			/*
		*/ label("Random number seed")				/*
		*/ option("seed")					/*
		*/

END

PROGRAM permute_options
BEGIN
	put "permute "
	require main.vn_pervar
	put main.vn_pervar " "
	option main.ck_b
	option main.ck_se
	put " " main.ed_explst
	beginoptions
		optionarg main.sp_reps
		option radio(main rb_two rb_left rb_right)
		optionarg /hidedefault rpt.sp_level

		option rpt.ck_noheader
		option rpt.ck_nolegend
		option rpt.ck_verbose
		option rpt.ck_nodrop
		option rpt.ck_qui
		option rpt.ck_noi
		option rpt.ck_trace
		optionarg rpt.ed_title
		INCLUDE _noomitted_pr
		INCLUDE _vsquish_pr
		INCLUDE _factor_vars_reporting_pr

		INCLUDE _saving_pr
		optionarg opt.vl_strata
		optionarg adv.en_eps
		option adv.ck_nowarn
		option adv.ck_force
		optionarg adv.ed_reject
		optionarg adv.ed_seed
	endoptions
END

PROGRAM command
BEGIN
	put /program permute_options
	put " " " : "	/* end of prefix, begin command */
		require main.vl_cmd
		put main.vl_cmd
END
