/*
	asmprobit_estat

*!  VERSION 1.2.3  18mar2011

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

*/

VERSION 12.0

INCLUDE _std_large
DEFINE _dlght 360	//dialog length for bootstrap options
INCLUDE header

HELP hlp1, view("help asmprobit postestimation")
RESET res1

SCRIPT PREINIT
BEGIN
	create BOOLEAN has_FactorVars
	has_FactorVars.setfalse
END

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

  DEFINE holdy 110

  // alternatives options
  TEXT     tx_altnote		_lft	holdy	_iwd	.,		///
  	label("Click OK or Submit to display the alternative summary statistics")

  // correlation options
  GROUPBOX gb_style		_lft	holdy	_iwd	_ht14h,		///
	label("Style")
  TEXT     tx_border    	_ilft	_ss	_ibwd	.,		///
	label("Border style:")
  COMBOBOX cb_border		@       _ss     200	.,		///
	label("Border style")						///
	dropdownlist default(all)					///
	contents(style_words)						///
	value(style_values)						///
	option(border)
  TEXT     tx_left		_ilft	_ls	_ibwd	.,  		///
	label("Left indent for tables:")
  SPINNER  sp_left	       @	_ss	_spwd	.,		///
	label("Left indent for tables")					///
	min(0) max(80) default(2) option(left)

  TEXT	   tx_style_format	_ilft	_ss	_ibwd	.,		///
	label("Display format:")
  EDIT     ed_corstyle_format	_ilft	_ss	175	.,		///
	option(format) label("Display format")
  BUTTON   bn_corstyle_format   +180    @       80      .,		///
	label("Create...") onpush(script showCorstyleFormatDialog)	///
	tooltip("Create display format")

  // + covariance options
  EDIT     ed_covstyle_format	_ilft	_ss	175	.,		///
	option(format) label("Display format")
  BUTTON   bn_covstyle_format   +180    @       80      .,		///
	label("Create...") onpush(script showCovstyleFormatDialog)	///
	tooltip("Create display format")

  // + facweights options
  EDIT     ed_facstyle_format	_ilft	_ss	175	.,		///
	option(format) label("Display format")
  BUTTON   bn_facstyle_format   +180    @       80      .,		///
	label("Create...") onpush(script showFacstyleFormatDialog)	///
	tooltip("Create display format")

  // mfx
  TEXT     tx_mfx1		_lft 	holdy	_iwd	.,		///
  	label(`"Click "OK" or "Submit" to obtain marginal effects using default settings."')
  TEXT     tx_mfx2		@	_ss 	@	.,		///
  	label(`"Click "Marginal effects" to launch a dialog box with all options."')
  BUTTON   bu_mfx		@	_ms	120	.,		///
  	onpush(view dialog asmprobit_mfx) 				///
  	label("Marginal effects...")

  // 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

SCRIPT showCorstyleFormatDialog
BEGIN
	create STRING corstyleFormatString
	create CHILD format_chooser
	format_chooser.setExitString corstyleFormatString
	format_chooser.setExitAction 			///
		"main.ed_corstyle_format.setvalue class corstyleFormatString.value"
END

SCRIPT showCovstyleFormatDialog
BEGIN
	create STRING covstyleFormatString
	create CHILD format_chooser
	format_chooser.setExitString covstyleFormatString
	format_chooser.setExitAction 			///
		"main.ed_covstyle_format.setvalue class covstyleFormatString.value"
END

SCRIPT showFacstyleFormatDialog
BEGIN
	create STRING facstyleFormatString
	create CHILD format_chooser
	format_chooser.setExitString facstyleFormatString
	format_chooser.setExitAction 			///
		"main.ed_facstyle_format.setvalue class facstyleFormatString.value"
END

INCLUDE _estat_bootstrap_pr
INCLUDE estat_vce_pr

LIST style_words
BEGIN
	"Around all four sides (default)"
	"No border lines are drawn"
	"At the top and bottom"
	"At the left and right"
	"At the left"
	"At the right"
	"At the top"
	"At the bottom"
END

LIST style_values
BEGIN
	all
	none
	rows
	columns
	left
	right
	top
	bottom
END

LIST main_subcommand_contents
BEGIN
  	 "Alternative summary statistics (alternatives)"
	 "Correlation matrix of the latent-variable errors for the alternatives (correlation)"
 	 "Covariance matrix of the latent-variable errors for the alternatives (covariance)"
	 "Variance-covariance factor weights matrix (facweights)"
 	 "Marginal effects (mfx)"
 	 "Information criteria (ic)"
 	 "Summarize estimation sample (summarize)"
 	 "Covariance matrix estimates (vce)"
END

LIST main_subcommand_values
BEGIN
	alternatives
	correlation
	covariance
	facweights
	mfx
	ic
	summarize
	vce
END

LIST main_subcommand_scripts
BEGIN
	script sel_alternatives
	script sel_correlation
	script sel_covariance
	script sel_facweights
	script sel_mfx
	script sel_ic
	script sel_summarize
	script sel_vce
END

SCRIPT sel_alternatives
BEGIN
	script main_hide_all
	main.tx_altnote.show
END

SCRIPT sel_correlation
BEGIN
	script main_hide_all
	main.gb_style.setposition . . . 175
	script correlation_on
END

SCRIPT sel_covariance
BEGIN
	script main_hide_all
	main.gb_style.setposition . . . 175
	script covariance_on
END

SCRIPT sel_facweights
BEGIN
	script main_hide_all
	main.gb_style.setposition . . . 175
	script facweights_on
END

SCRIPT sel_mfx
BEGIN
	script main_hide_all
	main.tx_mfx1.show
	main.tx_mfx2.show
	main.bu_mfx.show
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 correlation_on
BEGIN
	main.tx_style_format.setposition    . 130 . .
	main.ed_corstyle_format.setposition . 150 . .
	main.bn_corstyle_format.setposition . 150 . .
	main.tx_style_format.show
	main.ed_corstyle_format.show
	main.bn_corstyle_format.show

	main.tx_border.setposition . 180 . .
	main.cb_border.setposition . 200 . .
	main.tx_left.setposition   . 230 . .
	main.sp_left.setposition   . 250 . .
	main.gb_style.show
	main.tx_border.show
	main.cb_border.show
	main.tx_left.show
	main.sp_left.show
	main.ed_covstyle_format.hide
	main.bn_covstyle_format.hide
	main.ed_facstyle_format.hide
	main.bn_facstyle_format.hide
END

SCRIPT covariance_on
BEGIN
	main.tx_style_format.setposition    . 130 . .
	main.ed_covstyle_format.setposition . 150 . .
	main.bn_covstyle_format.setposition . 150 . .
	main.tx_style_format.show
	main.ed_covstyle_format.show
	main.bn_covstyle_format.show

	main.tx_border.setposition . 180 . .
	main.cb_border.setposition . 200 . .
	main.tx_left.setposition   . 230 . .
	main.sp_left.setposition   . 250 . .
	main.gb_style.show
	main.tx_border.show
	main.cb_border.show
	main.tx_left.show
	main.sp_left.show
	main.ed_corstyle_format.hide
	main.bn_corstyle_format.hide
	main.ed_facstyle_format.hide
	main.bn_facstyle_format.hide
END

SCRIPT facweights_on
BEGIN
	main.tx_style_format.setposition    . 130 . .
	main.ed_facstyle_format.setposition . 150 . .
	main.bn_facstyle_format.setposition    . 150 . .
	main.tx_style_format.show
	main.ed_facstyle_format.show
	main.bn_facstyle_format.show

	main.tx_border.setposition . 180 . .
	main.cb_border.setposition . 200 . .
	main.tx_left.setposition   . 230 . .
	main.sp_left.setposition   . 250 . .
	main.gb_style.show
	main.tx_border.show
	main.cb_border.show
	main.tx_left.show
	main.sp_left.show
	main.ed_corstyle_format.hide
	main.bn_corstyle_format.hide
	main.ed_covstyle_format.hide
	main.bn_covstyle_format.hide
END

SCRIPT non_basic_opt_off
BEGIN
	main.tx_style_format.hide
	main.ed_corstyle_format.hide
	main.ed_covstyle_format.hide
	main.bn_covstyle_format.hide
	main.bn_corstyle_format.hide
	main.ed_facstyle_format.hide
	main.bn_facstyle_format.hide
	main.gb_style.hide
	main.tx_border.hide
	main.cb_border.hide
	main.tx_left.hide
	main.sp_left.hide
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
BEGIN
	main.ck_n.hide
	main.sp_n.hide
	main.tx_altnote.hide
	program vce_off
	script main_summ_off
	script non_basic_opt_off
	script main_bootstrap_hide

	main.tx_mfx1.hide
	main.tx_mfx2.hide
	main.bu_mfx.hide
END

PROGRAM vl_output
BEGIN
	put main.vl_spec
END

PROGRAM vl_eq_output
BEGIN
	put main.vl_eq
END

PROGRAM command
BEGIN
	put "estat "
	put main.lb_subcmd
	if main.rb_spec {
		require main.vl_spec
		put " " main.vl_spec
	}
	beginoptions
		// non-basic options
		optionarg /hidedefault main.ed_corstyle_format
		optionarg /hidedefault main.ed_covstyle_format
		optionarg /hidedefault main.ed_facstyle_format
		optionarg /hidedefault main.cb_border
		optionarg /hidedefault main.sp_left

		// 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
