/*
  jackknife

*!  VERSION 2.2.0  28sep2010

*/

VERSION 12.0

INCLUDE _std_large
DEFINE	_dlght 440
INCLUDE header
HELP hlp1, view("help jackknife")
RESET res1


DIALOG main, label("jackknife - Jackknife estimation") tabtitle("Main")
BEGIN
  DEFINE _y _top
  INCLUDE _cmd_exp_list

  GROUPBOX gb_n      _lft      _xls     _iwd      _ht8,		/*
*/ label("Where are the number of observations used in the calculation stored?")/*
		*/
  RADIO    rb_empty  _indent   _ss       _inwd     .,			/*
		*/ first						/*
		*/ label("Automatically determined by jackknife")	/*
		*/ clickon("gaction main.ed_n.disable")			/*
		*/ option("NONE")					/*
		*/
  RADIO    rb_eclass @         _ss       @         .,			/*
		*/ label("Saved in e(N)")				/*
		*/ clickon("gaction main.ed_n.disable")			/*
		*/ option("eclass")					/*
		*/
  RADIO    rb_rclass @         _ss       @         .,			/*
		*/ label("Saved in r(N)")				/*
		*/ clickon("gaction main.ed_n.disable")			/*
		*/ option("rclass")					/*
		*/
  RADIO    rb_n      @         _ss       _cwd2     .,			/*
		*/ last							/*
		*/ label("User-specified alternative:")			/*
		*/ clickon("gaction main.ed_n.enable")			/*
		*/ option("NONE")					/*
		*/
  EDIT     ed_n      _lft2     @         @         .,			/*
		*/ label("n() option")					/*
		*/ option("n")						/*
		*/
END

INCLUDE ifin
INCLUDE weights_fpi

DIALOG opt, tabtitle("Options")
BEGIN
  CHECKBOX ck_clust  _lft      _top      _iwd      _ht8,		/*
		*/ label("Cluster variables")				/*
		*/ clickon("script opt_cl_on")				/*
		*/ clickoff("script opt_cl_off")			/*
		*/ groupbox						/*
		*/
  VARLIST  vl_clust  _indent   _ls       _inwd     .,			/*
		*/ label("Cluster variables")				/*
		*/ option("cluster")					/*
		*/
  TEXT     tx_clid   @         _ls       _cwd3     .,			/*
		*/ label("New cluster ID variable: (optional)")		/*
		*/
  EDIT     ed_clid   @         _ss       _cwd3     .,			/*
		*/ label("New cluster ID variable")			/*
		*/ option("idcluster")					/*
		*/

  DEFINE _y _xls
  INCLUDE _saving

  CHECKBOX ck_keep   _lft      _xxls     _cwd3_1   .,			/*
		*/ label("Keep pseudovalues")				/*
		*/ option("keep")					/*
		*/
  CHECKBOX ck_mse    _lft3_2   @         _comb3_1  .,			/*
		*/ label("Use MSE formula for variance estimation")	/*
		*/ option("mse")					/*
		*/
END

SCRIPT opt_cl_on
BEGIN
  opt.vl_clust.enable
  opt.tx_clid.enable
  opt.ed_clid.enable

END

SCRIPT opt_cl_off
BEGIN
  opt.vl_clust.disable
  opt.tx_clid.disable
  opt.ed_clid.disable

END

INCLUDE _saving_sc

SCRIPT rpt_POSTINIT
BEGIN
	create STRING rpt_bu_fmtcoefResults
	program rpt_bu_fmtcoef_ckResults

        create STRING rpt_bu_eformResults
        program rpt_bu_eform_ckResults
END

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

  DEFINE _x _lft
  DEFINE _y _ls
  DEFINE _xwd _cwd1
  INCLUDE _coef_table_common

  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 _lft
  DEFINE _y _xxxls
  INCLUDE _bu_coef_table_reporting

  DEFINE _x _lft2
  DEFINE _y @
  INCLUDE _bu_eform_opts_reporting

  DEFINE _x _lft2
  DEFINE _cx _cwd1
  DEFINE _y _top
  DEFINE _cy _ht6
  INCLUDE _output_reps
END

INCLUDE _coef_table_common_report_pr
INCLUDE fmt_coef_table_reporting_pr
INCLUDE eform_option_reporting_pr

DIALOG adv, tabtitle("Advanced")
BEGIN
  CHECKBOX ck_nodrop _lft      _top      @         .,			/*
		*/ label("Do not drop observations")			/*
		*/ option("nodrop")					/*
		*/

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

PROGRAM jknife_options
BEGIN
	beginoptions
		option radio(main rb_empty rb_rclass rb_eclass rb_n)
		if main.rb_n {
			require main.ed_n
			optionarg main.ed_n
		}
		if opt.ed_clid {
			require opt.vl_clust
		}
		optionarg opt.vl_clust
		optionarg opt.ed_clid
		option rpt.ck_qui
		option rpt.ck_noi
		option rpt.ck_trace
		INCLUDE _saving_pr
		option opt.ck_keep
		option opt.ck_mse
		put " "
		put /program _coef_table_common_cmd
		optionarg /hidedefault rpt.sp_level
		optionarg rpt.ed_title
		INCLUDE _noomitted_pr
		INCLUDE _vsquish_pr
		INCLUDE _factor_vars_reporting_pr
		put " " rpt_bu_fmtcoefResults
		put " " rpt_bu_eformResults
		option adv.ck_nodrop
		optionarg adv.ed_reject
	endoptions
END

PROGRAM command
BEGIN
	put "jackknife "
	option main.ck_b
	option main.ck_se
	put " "main.ed_explst
	put " " /program ifin_output
	put " " /program weights_output
	put /program jknife_options
	put " " " : "	/* end of prefix, begin command */
		require main.vl_cmd
		put main.vl_cmd
END
