/*
  estimates table

*!  VERSION 1.2.6  11may2011

*/

VERSION 12.0

INCLUDE _std_large
INCLUDE _ht320
INCLUDE header
HELP hlp1, view("help estimates table")
RESET res1

DIALOG main, label("estimates table -  Compare estimation results")	/*
	*/ tabtitle("Main")
BEGIN
  TEXT     tx_name         _lft      _top       _iwd     .,		/*
  		*/label("Estimates: (leave blank for most recent)")
  COMBOBOX cb_name         @         _ss        @        .,		/*
  		*/label("Estimates")					/*
  		*/dropdown append contents(estimates)
  GROUPBOX gb_opt          @         _xls        @        _ht12h,	/*
  		*/label("Additional statistics to be displayed in the table")
  CHECKBOX ck_chi2         _ilft     _ss        _cwd3    .,		/*
  		*/label("Model chi-squared") option(chi2)
  DEFINE holdy @y
  CHECKBOX ck_df           @         _ss        @        .,		/*
  		*/label("Model degrees of freedom") option(df)
  CHECKBOX ck_nobs         @         _ss        @        .,		/*
  		*/label("Number of observations") option(N)
  CHECKBOX ck_aic          _lft2     holdy      @        .,		/*
  		*/label("Akaike's information criterion") option(aic)
  CHECKBOX ck_bic          @         _ss        @        .,		/*
  		*/label("Schwarz's information criterion") option(bic)
  CHECKBOX ck_rank         @         _ss        @        .,		/*
  		*/label("Rank of e(V) -- number of free") option(rank)
  TEXT     tx_rank         _cksep    _vss       _inwd    .,		/*
  		*/label("parameters in model")
  TEXT     tx_stats2       _ilft     _ms        _ibwd    .,		/*
  	*/label("Other statistics from e() to be displayed in the table:")
  EDIT     ed_stats        _ilft     _ss        @        .,		/*
  	*/label("Additional statistics from e() to be displayed in the table")/*
  		*/option(stats)
  CHECKBOX ck_star         _lft      _xxls       _iwd      .,		/*
  	*/label("Denote significance of coefficients with stars")	/*
  	*/clickon(program star_on) clickoff(program star_off)		/*
	*/option(star)
  TEXT     tx_star         _indent2  _ss        _inwd    .,		/*
*/label("*: p < .05, **: p < .01, ***: p < .001 or use these thresholds:")
  EDIT     ed_star         @         _ss        @        .,		/*
  	*/label("Denote significance of coefficients with stars")	/*
  		*/default(".05 .01 .001") option("star")
END

DIALOG opt, label("") /*
		*/ tabtitle("Options")
BEGIN
  /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+*/
  CHECKBOX ck_keep         _lft      _top       _iwd     .,		/*
  	*/label("Make a table of these coefficients in this order:")	/*
  	*/clickon(script keep_on) clickoff(script keep_off)
  VARLIST  vl_keep         @         _ss        @        .,		/*
  	*/label("Make a table of these coefficients in this order")	/*
  	*/option(keep)
  TEXT     tx_keep         @         _ss        @        .,		/*
*/label(`"Specify variable names (e.g. "price"), equation names (e.g. "mean:")"')
  TEXT     tx_keep2        @         _vss       @        .,		/*
  */label(`"or full names (e.g. "mean:price")"')
  CHECKBOX ck_drop         @         _ms        @        .,		/*
  */label("Drop these coefficients from the table:")			/*
  		*/clickon(script drop_on) clickoff(script drop_off)
  VARLIST  vl_drop         @         _ss        @        .,		/*
  		*/label("Drop these coefficients from the table")	/*
  		*/option(drop)
  TEXT     tx_drop         @         _ss        @        .,		/*
*/label(`"Same specification as above plus "_cons" will drop _cons from all equations"')
  GROUPBOX gb_match        @         _ls        @        _ht8,		/*
  		*/label("Match equations from different models this way:")
  RADIO    rb_mat1         _ilft     _ss        _ibwd    .,		/*
  		*/label("Match equations by name") option(NONE)	/*
  		*/clickon(script opt_mat3_off) first
  RADIO    rb_mat2         @         _ss        @        .,		/*
  	*/label("Match first equations of models, the rest by names")	/*
  		*/option("equations(1)") clickon(script opt_mat3_off)
  RADIO    rb_mat3         @         _ss        @        .,		/*
  		*/label("Custom equation matching:")			/*
  		*/clickon(script opt_mat3_on) option(NONE) last
  EDIT     ed_mat3         _indent2  _ss        _edifwd .,		/*
  		*/label("Customize equation matching") option(equations)
  BUTTON   bu_mat3         _edifsep  @          _buwd    .,		/*
  		*/label("Help") onpush("view help est_table_equations##|_new")
END

SCRIPT bfmt_get
BEGIN
	create STRING bfmtResult
	create CHILD format_chooser
	format_chooser.setExitString bfmtResult
	format_chooser.setExitAction "nopt.ed_b.setvalue class bfmtResult.value"
END

SCRIPT sefmt_get
BEGIN
	create STRING sefmtResult
	create CHILD format_chooser
	format_chooser.setExitString sefmtResult
	format_chooser.setExitAction "nopt.ed_se.setvalue class sefmtResult.value"
END

SCRIPT tfmt_get
BEGIN
	create STRING tfmtResult
	create CHILD format_chooser
	format_chooser.setExitString tfmtResult
	format_chooser.setExitAction "nopt.ed_t.setvalue class tfmtResult.value"
END

SCRIPT pfmt_get
BEGIN
	create STRING pfmtResult
	create CHILD format_chooser
	format_chooser.setExitString pfmtResult
	format_chooser.setExitAction "nopt.ed_p.setvalue class pfmtResult.value"
END

SCRIPT stfmt_get
BEGIN
	create STRING stfmtResult
	create CHILD format_chooser
	format_chooser.setExitString stfmtResult
	format_chooser.setExitAction "nopt.ed_stfmt.setvalue class stfmtResult.value"
END

DIALOG nopt, label("") tabtitle("Numerical formats")
BEGIN
  TEXT     tx_b            _lft      _top       _cken7r2 .,		/*
  		*/label("Coefficients:")
  EDIT     ed_b            +20 	     _ss        _en14wd  .,		/*
  		*/label("Format for coefficients")			/*
  		*/option(b)
  BUTTON   bu_bfmt         _en14sep  @          60       .,		/*
		*/label("Format...") onpush(script bfmt_get)		/*
		*/tooltip("Create display format")
  
  CHECKBOX ck_se           _lft     _ls        _cken7r2 .,		/*
  		*/label("Report standard errors")			/*
  		*/clickon(script se_on) clickoff(script se_off) option(se)
  EDIT     ed_se           +20      _ss        _en14wd  .,		/*
  		*/label("Standard errors")				/*
  		*/option(se)
  BUTTON   bu_sefmt        _en14sep @          60       .,		/*
		*/label("Format...") onpush(script sefmt_get)		/*
		*/tooltip("Create display format")

  CHECKBOX ck_t            _lft     _ls        _cken7r2 .,		/*
  		*/label("Report t- or z-statistics")			/*
  		*/clickon(script t_on) clickoff(script t_off) option(t)
  EDIT     ed_t            +20      _ss        _en14wd  .,		/*
  		*/label("T- or z-values")				/*
  		*/option(t)
  BUTTON   bu_tfmt         _en14sep  @         60       .,		/*
		*/label("Format...") onpush(script tfmt_get)		/*
		*/tooltip("Create display format")

  CHECKBOX ck_p            _lft     _ls        _cken7r2 .,		/*
  		*/label("Report p-values")				/*
  		*/clickon(script p_on) clickoff(script p_off) option(p)
  EDIT     ed_p            +20      _ss        _en14wd  .,		/*
  		*/label("(Two-sided) p-value")				/*
  		*/option(p)
  BUTTON   bu_pfmt         _en14sep  @         60       .,		/*
		*/label("Format...") onpush(script pfmt_get)		/*
		*/tooltip("Create display format")

  TEXT     tx_stfmt        _lft     _ls        _cken7r2 .,		/*
  		*/label("Scalar statistics:")
  EDIT     ed_stfmt        +20      _ss        _en14wd  .,		/*
  		*/label("Scalar statistics")				/*
  		*/option(stfmt)
  BUTTON   bu_stfmt2       _en14sep  @         60       .,		/*
		*/label("Format...") onpush(script stfmt_get)		/*
		*/tooltip("Create display format")
END

DIALOG opt2, label("") /*
		*/ tabtitle("General format")
BEGIN
  /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+*/
  SPINNER  sp_varw         _lft      _top       _spwd    .,		/*
  		*/label("Characters in displayed names of vars and stats")/*
  		*/default(12) min(1) max(80) option(varwidth)
  TEXT     tx_varw         _spsep    @          _spr     .,		/*
  */label("Number of characters to display for names of variables and statistics")
  SPINNER  sp_modw         _lft      _ls        _spwd    .,		/*
  		*/label("Characters in displayed model names")		/*
  		*/default(12) min(1) max(80) option(modelwidth)
  TEXT     tx_modw         _spsep    @          _spr     .,		/*
  		*/label("Number of characters to display for model names")
  CHECKBOX ck_eform        _lft      _ls        _iwd     .,		/*
  		*/label("Display coefficient table in exponentiated form")/*
  		*/option(eform)
  CHECKBOX ck_label        @         _ms        _iwd     .,		/*
  	*/label("Display variable labels instead of variable names")	/*
  		*/option(label)
  CHECKBOX ck_newpanel     @         _ms        _iwd     .,		/*
*/label("Display statistics in separate table from the one with coefficients")/*
		*/option(newpanel)
  GROUPBOX gb_style        @         _ls        @        _ht6,		/*
  		*/label("Style of the coefficients table:")		/*
		*/
  RADIO    rb_onel         _indent   _ss        _ibwd    .,		/*
*/label("Display vertical line after the variables, but not between the models")/*
  		*/first option("style(oneline)")
  RADIO    rb_col          @         _ss        @        .,		/*
*/label("Display vertical lines after each column (variable names, models)")/*
  		*/option("style(columns)")
  RADIO    rb_nol          @         _ss        @        .,		/*
  		*/label("Suppress all vertical lines")			/*
  		*/option("style(nolines)") last
  CHECKBOX ck_coded        _lft      _xls       _iwd     .,		/*
  		*/label("Display a compact table") option(coded) 	/*
  		*/onclickon(script opt2_coded_on) 			/*
		*/onclickoff(program opt2_coded_off)
END

SCRIPT opt2_coded_on
BEGIN
	opt2.rb_nol.disable
	opt2.rb_col.disable
	opt2.rb_onel.disable
	opt2.gb_style.disable
	opt2.ck_newpanel.disable
	opt2.ck_label.disable
	opt2.ck_eform.disable
	opt2.tx_modw.disable
	opt2.sp_modw.disable
	opt2.tx_varw.disable
	opt2.sp_varw.disable
	nopt.tx_b.disable
	nopt.ed_b.disable
	nopt.bu_bfmt.disable
	nopt.ck_se.disable
	nopt.ed_se.disable
	nopt.bu_sefmt.disable
	nopt.ck_t.disable
	nopt.ed_t.disable
	nopt.bu_tfmt.disable
	nopt.ck_p.disable
	nopt.ed_p.disable
	nopt.bu_pfmt.disable
	nopt.tx_stfmt.disable
	nopt.ed_stfmt.disable
	nopt.bu_stfmt2.disable
	main.ed_star.disable
	main.tx_star.disable
	main.ck_star.disable
END

PROGRAM opt2_coded_off
BEGIN
	call gaction opt2.rb_nol.enable
	call gaction opt2.rb_col.enable
	call gaction opt2.rb_onel.enable
	call gaction opt2.gb_style.enable
	call gaction opt2.ck_newpanel.enable
	call gaction opt2.ck_label.enable
	call gaction opt2.ck_eform.enable
	call gaction opt2.tx_modw.enable
	call gaction opt2.sp_modw.enable
	call gaction opt2.tx_varw.enable
	call gaction opt2.sp_varw.enable
	call gaction nopt.tx_b.enable
	call gaction nopt.ed_b.enable
	call gaction nopt.bu_bfmt.enable
	call gaction nopt.ck_se.enable
	if nopt.ck_se {
		call gaction nopt.ed_se.enable
		call gaction nopt.bu_sefmt.enable
	}
	call gaction nopt.ck_t.enable
	if nopt.ck_t {
		call gaction nopt.ed_t.enable
		call gaction nopt.bu_tfmt.enable
	}
	call gaction nopt.ck_p.enable
	if nopt.ck_p {
		call gaction nopt.ed_p.enable
		call gaction nopt.bu_pfmt.enable
	}
	call gaction nopt.tx_stfmt.enable
	call gaction nopt.ed_stfmt.enable
	call gaction nopt.bu_stfmt2.enable
	call gaction main.tx_star.enable
	call gaction main.ck_star.enable
	if main.ck_star {
		call gaction main.ed_star.enable
	}
END

SCRIPT opt_mat3_off
BEGIN
	opt.ed_mat3.disable
	opt.bu_mat3.disable
END

SCRIPT opt_mat3_on
BEGIN
	opt.ed_mat3.enable
	opt.bu_mat3.enable
END

PROGRAM star_on
BEGIN
	call main.ed_star.enable
	if nopt.ck_se {
		call script se_off
	}
	call nopt.ck_se.disable
	if nopt.ck_t {
		call script t_off
	}
	call nopt.ck_t.disable
	if nopt.ck_p {
		call script p_off
	}
	call nopt.ck_p.disable
END

PROGRAM star_off
BEGIN
	call main.ed_star.disable
	call nopt.ck_se.enable
	if nopt.ck_se {
		call script se_on
	}
	call nopt.ck_t.enable
	if nopt.ck_t {
		call script t_on
	}
	call nopt.ck_p.enable
	if nopt.ck_p {
		call script p_on
	}
END

SCRIPT keep_on
BEGIN
	opt.vl_keep.enable
END

SCRIPT keep_off
BEGIN
	opt.vl_keep.disable
END

SCRIPT drop_on
BEGIN
	opt.vl_drop.enable
END

SCRIPT drop_off
BEGIN
	opt.vl_drop.disable
END

SCRIPT se_on
BEGIN
	nopt.ed_se.enable
	nopt.bu_sefmt.enable
END

SCRIPT se_off
BEGIN
	nopt.ed_se.disable
	nopt.bu_sefmt.disable
END

SCRIPT t_on
BEGIN
	nopt.ed_t.enable
	nopt.bu_tfmt.enable
END

SCRIPT t_off
BEGIN
	nopt.ed_t.disable
	nopt.bu_tfmt.disable
END

SCRIPT p_on
BEGIN
	nopt.ed_p.enable
	nopt.bu_pfmt.enable
END

SCRIPT p_off
BEGIN
	nopt.ed_p.disable
	nopt.bu_pfmt.disable
END


PROGRAM additional_stats_output
BEGIN
	option main.ck_chi2
	option main.ck_df
	option main.ck_nobs
	option main.ck_aic
	option main.ck_bic
	option main.ck_rank
	put main.ed_stats
END

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

  DEFINE _x _lft
  DEFINE _y _ms
  DEFINE _cx _iwd
  INCLUDE _noomitted

  DEFINE _x _lft
  DEFINE _y _ms
  DEFINE _cx _iwd
  INCLUDE _vsquish

  DEFINE _x _lft
  DEFINE _y _ls
  DEFINE _cx _iwd
  INCLUDE _factor_vars_reporting

END

PROGRAM command
BEGIN
	put "estimates table "
	put main.cb_name
	beginoptions
		if main.ck_chi2 | main.ck_df | main.ck_nobs | 	///
			main.ck_aic | main.ck_bic |		///
			main.ck_rank | main.ed_stats  {
			put " stats("
			put /program additional_stats_output
			put ") "
		}
		if main.ck_star{
			put "star"
			if main.ed_star {
				put "(" main.ed_star ") "
			}
		}
		if opt.ck_keep {
			require opt.vl_keep
			optionarg opt.vl_keep
		}
		if opt.ck_drop {
			require opt.vl_drop
			optionarg opt.vl_drop
		}
		if !opt2.ck_coded {
			option radio (opt rb_mat1 rb_mat2 rb_mat3)
		}
		if opt.rb_mat3 {
			optionarg opt.ed_mat3
		}
		optionarg /hidedefault nopt.ed_b
		if nopt.ck_se{
			if !default(nopt.ed_se) {
				put " se(" nopt.ed_se ") "
			}
			if default(nopt.ed_se) {
				put " se"
			}
		}
		if nopt.ck_t{
			if !default(nopt.ed_t) {
				put " t(" nopt.ed_t ") "
			}
			if default(nopt.ed_t) {
				put " t"
			}
		}
		if nopt.ck_p{
			if !default(nopt.ed_p) {
				put " p(" nopt.ed_p ") "
			}
			if default(nopt.ed_p) {
				put " p"
			}

		}
		optionarg /hidedefault nopt.ed_stfmt
		option opt2.ck_eform
		optionarg /hidedefault opt2.sp_varw
		optionarg /hidedefault opt2.sp_modw
		option opt2.ck_label
		if !opt2.ck_coded {
			option radio(opt2 rb_onel rb_col rb_nol)
		}
		option opt2.ck_newpanel
		option opt2.ck_coded
		INCLUDE _nocnsreport_pr
		INCLUDE _noomitted_pr
		INCLUDE _vsquish_pr
		INCLUDE _factor_vars_reporting_pr
	endoptions

END
