/*
    vec.dlg

*!  VERSION 1.0.8  23aug2010

*/

VERSION 12.0

INCLUDE _std_large
DEFINE _dlght 340
INCLUDE header
HELP hlp1, view("help vec")
RESET res1

DIALOG model, tabtitle("Model") ///
	label("vec - Vector error-correction models")
BEGIN
  DEFINE _x _xsetbu
  DEFINE _y _top
  INCLUDE _bu_tsset

  TEXT     tx_dv             _lft      _topph    129       .,		/*
		*/ label("Dependent variables:")
  VARLIST  vl_dv             @         _ss       _iwd      .,		/*
		*/ label("Dependent variables") ts

  SPINNER  sp_rank           @           +35       _spwd       .,	///
  		default(1) min(1) option(rank)
  TEXT     tx_rank           _spsep      @         _spr        ., 	///
  		label("Number of cointegrating equations (rank)")

  SPINNER  sp_lags           _lft        _ls       _spwd       .,	///
  		default(2) min(1) option(lags)
  TEXT     tx_lags           _spsep      @         _spr        .,	///
  		label("Maximum lag to be included in underlying VAR model")

  TEXT     tx_trend          _lft        _ls       _cwd1       .,	///
  		label("Trend specification:")
  COMBOBOX cb_trend          @           _ss       _vnwd       .,	///
  		dropdownlist 						///
  		option(trend) contents(trend_spec) default(constant) 	///
  		onselchangelist(trend_action)

  GROUPBOX gb_const          _lft        +35       _iwd        _ht9h,	///
  		label("Constraints")

  BUTTON   bu_constraint     _xsetbu     _ss       110         .,	///
  		label("New constraints...")				///
		onpush(view dialog cons_define)				///
		tooltip("Define new constraints")

  CHECKBOX ck_bconstraint    _ilft       @         _comb4_3    .,	///
  		onclickon(program bconstant_on)				///
  		onclickoff(program bconstant_off)			///
  		label("Constraints to place on cointegrating vectors:")
  COMBOBOX cb_bconstraint    @           _ss       @           .,	///
  		append							///
		dropdown						///
		contents(constraint)					///
		option(bconstraints) 					///
  		label("Constraints to place on cointegrating vectors")

  CHECKBOX ck_aconstraint    _ilft       _ls       _comb4_3    .,	///
  		onclickon(program aconstant_on)				///
  		onclickoff(program aconstant_off)			///
  		label("Constraints to place on adjustment parameters:")
  COMBOBOX cb_aconstraint    @           _ss       @           .,	///
  		append							///
		dropdown						///
		contents(constraint)					///
		option(aconstraints) 					///
  		label("Constraints to place on adjustment parameters")
END

LIST trend_spec
BEGIN
	trend
	rtrend
	constant
	rconstant
	none
END

LIST trend_action
BEGIN
	model2.vl_sindicator.enable
	model2.vl_sindicator.enable
	model2.vl_sindicator.enable
	model2.vl_sindicator.disable
	model2.vl_sindicator.disable
END

PROGRAM bconstant_on
BEGIN
	call model.cb_bconstraint.enable
	call script tab_max_enable
END

PROGRAM bconstant_off
BEGIN
	call model.cb_bconstraint.disable
	if ! model.ck_aconstraint {
		call script tab_max_disable
	}
END

PROGRAM aconstant_on
BEGIN
	call model.cb_aconstraint.enable
	call script tab_max_enable
END

PROGRAM aconstant_off
BEGIN
	call model.cb_aconstraint.disable
	if ! model.ck_bconstraint {
		call script tab_max_disable
	}
END

DIALOG model2, tabtitle("Adv. model")
BEGIN
  GROUPBOX gb_advanced       _lft        _top      _iwd      _ht9,	///
  		label("Advanced model options")
  TEXT     tx_sindicator     _ilft       _ss       _inwd     .,		///
		label("Normalized seasonal indicator variables:")
  VARLIST  vl_sindicator     @           _ss       @         .,		///
  		option(sindicators)					///
		label("Normalized seasonal indicator variables")

  CHECKBOX ck_noreduce       @           _ls       @         .,		///
  		option(noreduce)					///
  		label("Do not perform checks and corrections for collinearity among lags of")
  TEXT     tx_noreduce       _indent2    _vss      _inwd     .,		///
  		label("dependent variables")
END

INCLUDE byifin

SCRIPT rpt_POSTINIT
BEGIN
	create STRING rpt_bu_fmtcoefResults
	program rpt_bu_fmtcoef_ckResults
END

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

  CHECKBOX ck_nobtable       _lft      _ls       _iwd      .,		///
  		option(nobtable)					///
  		label("Suppress reporting of parameters in the cointegrating equations")
  CHECKBOX ck_noidtest       @         _ms       @         .,		///
  		option(noidtest)					///
  		label("Suppress reporting of the likelihood-ratio test of overidentifying restrictions")
  CHECKBOX ck_alpha          @         _ms       @         .,		///
  		option(alpha)						///
  		label("Report adjustment parameters")
  CHECKBOX ck_pi             @         _ms       @         .,		///
  		option(pi)						///
  		onclickon(rpt.ck_noptable.disable)			///
  		onclickoff(rpt.ck_noptable.enable)			///
  		label("Report parameters in pi")
  CHECKBOX ck_noptable       @         _ms       @         .,		///
  		option(noptable)					///
  		onclickon(rpt.ck_pi.disable)				///
  		onclickoff(rpt.ck_pi.enable)				///
  		label("Suppress reporting elements of pi matrix")
  CHECKBOX ck_mai            @         _ms       @         .,		///
  		option(mai)						///
  		label("Report parameters in the moving-average impact matrix")
  CHECKBOX ck_noetable       @         _ms       @         .,		///
  		option(noetable)					///
  		label("Suppress reporting of adjustment and short-run parameters")
  CHECKBOX ck_dforce         @         _ms       @         .,		///
  		option(dforce)						///
  		label("Force reporting of short-run, beta and alpha parameters when the parameters in")
  TEXT     tx_force          _indent2  _vss      _inwd     .,		///
  		label("beta are not identified (advanced option)")

  DEFINE _x _lft
  DEFINE _y _ms
  DEFINE _cx _iwd
  INCLUDE _nocnsreport

  DEFINE _x _lft
  DEFINE _y _ms
  DEFINE _cx _iwd
  INCLUDE _vsquish

  DEFINE _x _lft
  DEFINE _y _ls
  INCLUDE _bu_coef_table_reporting
END

INCLUDE fmt_coef_table_reporting_pr

DIALOG max, tabtitle("Maximization")
BEGIN
  SPINNER  sp_iter           _lft      _top      _spwd     .,		///
		label("Maximum iterations")				///
		min(1)							///
		max(16000)						///
		default(c(maxiter))					///
		option("iterate")

  TEXT     tx_iter           _spsep    @         _spr2     .,		///
		label("Maximum iterations")

  GROUPBOX gb_iterlog        _lft      _ls       _cwd3_1   _ht4,	///
		label("Iteration log")
  DEFINE holdy @y
  RADIO	   rb_log            _indent   _ss       _inwd     .,		///
  		first 							///
		onclickon(program showlog_on)				///
		label("Show log")
  RADIO	   rb_nolog          @         _ss       @	   .,		///
  		last option(nolog)					///
		onclickon(script showlog_off)				///
		label("Suppress log")

  GROUPBOX gb_addlog         _lft3_2   holdy     _comb3_1  _ht4,	///
		label("Additional iteration log results")
  CHECKBOX ck_trace          _indent   _ss       _inwd     .,		///
		label("Parameter estimates")				///
		option(trace)
  CHECKBOX ck_toltrace       @         _ss       @         .,		///
  		option(toltrace)					///
		label("Difference of log likelihood and coefficient")

  GROUPBOX gb_tolerence      _lft      _xls      _iwd      _ht5h,	///
		label("Convergence tolerances")
  EDIT     ed_tolerence      _ilft     _ss       _en7wd    .,		///
		label("Coefficient vector")				///
		option(tolerance) default(1e-7)
  TEXT     tx_tolerence      _en7sep   @         _en7rb    .,		///
		label("Coefficient vector (default = 1e-7)")
  EDIT     ed_ltolerence     _ilft     _ls       _en7wd    .,		///
		label("Log likelihood")					///
		option(ltolerance) default(1e-10)
  TEXT     tx_ltolerence     _en7sep   @         _en7rb    .,		///
		label("Log likelihood (default = 1e-10)")

  GROUPBOX gb_from           _lft      _xxls     _iwd      _ht6,	///
  		label("Starting values defined by row vectors")
  COMBOBOX cb_afrom          _ilft     _ms       _vnwd     .,		///
		option(afrom) dropdown					///
		contents(vector)
  TEXT     tx_afrom          _vnsep    @         _vnrb     .,		///
		label("Starting values of adjustment parameters")

  COMBOBOX cb_bfrom          _ilft     _ls       _vnwd     .,		///
		option(bfrom) dropdown					///
		contents(vector)
  TEXT     tx_bfrom          _vnsep    @         _vnrb     .,		///
		label("Starting values for the cointegrating equation parameters")

END

PROGRAM showlog_on
BEGIN
	if !D(max.rb_log) {
	// this test must be performed since this tab is initially disabled
		call max.ck_trace.enable
		call max.ck_toltrace.enable
		call max.gb_addlog.enable
	}
END

SCRIPT showlog_off
BEGIN
	max.ck_trace.disable
	max.ck_toltrace.disable
	max.gb_addlog.disable
END

// wrapper for program
SCRIPT tab_max_enable
BEGIN
	program tab_max_enable_pr
END

PROGRAM tab_max_enable_pr
BEGIN
	call max.sp_iter.enable
	call max.tx_iter.enable
	call max.gb_iterlog.enable
	call max.rb_log.enable
	call max.rb_nolog.enable
	if ! max.rb_nolog {
		call max.gb_addlog.enable
		call max.ck_trace.enable
		call max.ck_toltrace.enable
	}
	call max.gb_tolerence.enable
	call max.ed_tolerence.enable
	call max.tx_tolerence.enable
	call max.ed_ltolerence.enable
	call max.tx_ltolerence.enable
	call max.gb_from.enable
	call max.cb_afrom.enable
	call max.tx_afrom.enable
	call max.cb_bfrom.enable
	call max.tx_bfrom.enable
END

SCRIPT tab_max_disable
BEGIN
	max.sp_iter.disable
	max.tx_iter.disable
	max.gb_iterlog.disable
	max.rb_log.disable
	max.rb_nolog.disable
	max.gb_addlog.disable
	max.ck_trace.disable
	max.ck_toltrace.disable
	max.gb_tolerence.disable
	max.ed_tolerence.disable
	max.tx_tolerence.disable
	max.ed_ltolerence.disable
	max.tx_ltolerence.disable
	max.gb_from.disable
	max.cb_afrom.disable
	max.tx_afrom.disable
	max.cb_bfrom.disable
	max.tx_bfrom.disable
END

PROGRAM command
BEGIN
	require model.cb_bconstraint
	require model.cb_aconstraint
	put " " /program by_output
	put "vec "
	varlist model.vl_dv
	put " " /program ifin_output
	beginoptions
		optionarg model.cb_trend
		optionarg /hidedefault model.sp_rank
		optionarg /hidedefault model.sp_lags
		optionarg model.cb_bconstraint
		optionarg model.cb_aconstraint

		optionarg model2.vl_sindicator
		option model2.ck_noreduce

		optionarg /hidedefault rpt.sp_level
		option rpt.ck_nobtable
		option rpt.ck_noidtest
		option rpt.ck_alpha
		option rpt.ck_pi
		option rpt.ck_noptable
		option rpt.ck_mai
		option rpt.ck_noetable
		option rpt.ck_dforce
		INCLUDE _nocnsreport_pr
		INCLUDE _vsquish_pr
		put " " rpt_bu_fmtcoefResults

		optionarg /hidedefault max.sp_iter
		option max.rb_nolog
		option max.ck_trace
		option max.ck_toltrace
		optionarg /hidedefault max.ed_tolerence
		optionarg /hidedefault max.ed_ltolerence
		optionarg max.cb_afrom
		optionarg max.cb_bfrom
	endoptions
END
