/*
  estat after probit dprobit logit logistic

*!  VERSION 1.0.6  09jan2008

	***
	USE EXTREME CARE WHEN CHANGING CONTROL NAMES. The names used
	in this file have multiple external dependencies.
*/


DIALOG main, label("estat - Postestimation statistics") tabtitle("Main")
BEGIN
  TEXT     tx_subcmd		_lft	_top	_iwd	.,		///
  	label("Reports and statistics: (subcommand)")
  LISTBOX  lb_subcmd		@	_ss	@	70,		///
  	contents(main_subcommand_contents)				///
  	values(main_subcommand_values)					///
  	onselchangelist(main_subcommand_scripts)

  DEFINE holdy 110

  // classification
  GROUPBOX gb_sample		_lft	holdy	_iwd	_ht4,		///
  	label("Test sample")
  RADIO    rb_sample		_ilft	_ss	_ibwd	.,		///
	label("Use estimation sample") first
  RADIO    rb_all		@	_ss	@	.,		///
	label("Use all observations in the data")			///
	last option(all)
  EDIT     ed_cutoff		_lft	+45	_en7wd	.,		///
  	option(cutoff) default(0.5)
  TEXT     tx_cutoff		_en7sep	@	_en7r	.,		///
  	label("Positive outcome threshold; default 0.5")

  // gof
  GROUPBOX gb_test		_lft	holdy	_iwd	_ht6h,		///
	label("Test")
  RADIO    rb_pearson		_ilft	_ss	_ibwd	.,  		///
	label("Pearson goodness-of-fit") 				///
	first onclickon(script main_group_off)
  RADIO    rb_hosmer		@	_ss	_ibwd	.,		///
	label("Hosmer-Lemeshow goodness-of-fit")			///
	last onclickon(script main_group_on)
  SPINNER  sp_group		_indent2 _ms	_spwd	.,  		///
	label("Number of quantiles for grouping data")			///
	min(1) max(10000) default(10) option(group)
  TEXT     tx_group		_spsep	@	_cksprb	., 		///
	label("Number of quantiles for grouping data")

  CHECKBOX ck_outsample		_lft	+120	_iwd	.,		///
  	option(outsample)						///
  	label("Adjust degrees of freedom for samples outside estimation sample")
  CHECKBOX ck_table		@	_ms	@	.,		///
  	option(table)							///
  	label("Display table of groups used for test")

  // Information criteria
  CHECKBOX ck_n			_lft	holdy	_iwd	.,		///
	onclickon(main.sp_n.enable)					///
	onclickoff(main.sp_n.disable)					///
	label("Number of observations for calculating BIC")
  SPINNER sp_n			_indent2 _ss	_spwd	.,		///
	default(e(N)) min(1) max(e(N))					///
	option(n)

  // Summarize options
  GROUPBOX gb_eqlist            _lft    holdy	_iwd	_ht6,		///
  	label("Summarize")
  RADIO    rb_default		_ilft	_ss	_inwd	.,		///
  	first label("Use all variables involved in the estimation")	///
  	onclickon(main.vl_spec.disable)
  RADIO    rb_spec		@	_ss	@	.,		///
	onclickon(main.vl_spec.enable) last				///
	label("Use variables and optional equation names:")
  VARLIST  vl_spec	      _indent2	_ss	_inwd	.,		///
	label("Use variables and optional equation names")
  CHECKBOX ck_equation      	_lft	+45	_iwd	.,		///
	option(equation)						///
	label("Display summary by equation")
  CHECKBOX ck_labels		@	_ms	@	.,		///
  	label("Display variable labels")				///
  	option(labels)
  CHECKBOX ck_noheader		_lft	_ms	_iwd	.,		///
	option(noheader)						///
	label("Suppress the header")
  CHECKBOX ck_noweights		@	_ms	@	.,		///
	option(noweights)						///
	label("Ignore weights")

  INCLUDE estat_vce
  INCLUDE _estat_bootstrap
END

INCLUDE _estat_bootstrap_pr
INCLUDE estat_vce_pr

SCRIPT main_group_on
BEGIN
	main.sp_group.enable
	main.tx_group.enable
END
SCRIPT main_group_off
BEGIN
	main.sp_group.disable
	main.tx_group.disable
END

LIST main_subcommand_contents
BEGIN
	"Report various summary stats. including the classification table (classification)"
	"Pearson or Hosmer-Lemeshow goodness-of-fit test (gof)"
	"Display information criteria (ic)"
	"Summarize estimation sample (summarize)"
	"Covariance matrix estimates (vce)"
END

LIST main_subcommand_values
BEGIN
	classification
	gof
	ic
	summarize
	vce
END

LIST main_subcommand_scripts
BEGIN
	script sel_classification
	script sel_gof
	script sel_ic
	script sel_summarize
	script sel_vce
END

SCRIPT sel_classification
BEGIN
	script main_hide_all
	main.gb_sample.show
	main.rb_sample.show
	main.rb_all.show
	main.gb_sample.setposition . 110
	main.rb_sample.setposition . 130
	main.rb_all.setposition . 150
	main.ed_cutoff.show
	main.tx_cutoff.show
	script ifin_enable
	script weights_enable
END

SCRIPT sel_gof
BEGIN
	script main_hide_all
	main.gb_test.show
	main.rb_pearson.show
	main.rb_hosmer.show
	main.gb_sample.show
	main.rb_sample.show
	main.rb_all.show
	main.gb_sample.setposition . 215
	main.rb_sample.setposition . 235
	main.rb_all.setposition . 255
	main.sp_group.show
  	main.tx_group.show
	main.ck_outsample.show
  	main.ck_table.show
	script ifin_enable
	script weights_enable
END

SCRIPT sel_ic
BEGIN
	script main_hide_all
	main.ck_n.show
	main.sp_n.show
END

SCRIPT sel_summarize
BEGIN
	script main_hide_all
	script main_summ_on
END

SCRIPT sel_vce
BEGIN
	script main_hide_all
	program vce_on
END

SCRIPT main_summ_on
BEGIN
	main.ck_equation.show
	main.ck_labels.show
	main.ck_noheader.show
	main.ck_noweights.show
	main.gb_eqlist.show
	main.rb_default.show
	main.rb_spec.show
	main.vl_spec.show
END

SCRIPT main_summ_off
BEGIN
	main.ck_equation.hide
	main.ck_labels.hide
	main.ck_noheader.hide
	main.ck_noweights.hide
	main.gb_eqlist.hide
	main.rb_default.hide
	main.rb_spec.hide
	main.vl_spec.hide
END

SCRIPT main_hide_all  // MUST BE IMPLEMENTED FOR BOOTSTRAP
BEGIN
	main.gb_sample.hide
	main.rb_sample.hide
	main.rb_all.hide
	main.ed_cutoff.hide
	main.tx_cutoff.hide
	main.gb_test.hide
	main.rb_pearson.hide
	main.rb_hosmer.hide
	main.sp_group.hide
  	main.tx_group.hide
  	main.ck_outsample.hide
  	main.ck_table.hide
	script ifin_disable
	script weights_disable
	main.ck_n.hide
	main.sp_n.hide
	script main_summ_off
	program vce_off
	script main_bootstrap_hide
END

PROGRAM vl_output
BEGIN
	put main.vl_spec
END

PROGRAM vl_eq_output
BEGIN
	put main.vl_eq
END

INCLUDE ifin
INCLUDE weights_f

PROGRAM command
BEGIN
	put "estat "
	put main.lb_subcmd
	INCLUDE _ifin_pr
	INCLUDE _weights_pr

	if main.rb_spec {
		require main.vl_spec
		put " " main.vl_spec
	}

	beginoptions
		// classification
		option main.rb_all
		optionarg /hidedefault main.ed_cutoff
		// gof
		optionarg main.sp_group
		option main.ck_outsample
  		option main.ck_table
  
  		// ic options
		optionarg main.sp_n

		// Summarize options
		option main.ck_equation
		option main.ck_labels
		option main.ck_noheader
		option main.ck_noweights
		put " " /program vce_output
		put " " /program bootstrap_output
	endoptions

END
