/*
    fcast_compute.dlg

*!  VERSION 1.0.0  14jul2004

*/

VERSION 8.0

INCLUDE _std_large
INCLUDE header

HELP hlp1, view("help fcast_compute")
RESET res1

DIALOG main, label("fcast compute - Compute dynamic forecasts")	///
		tabtitle("Main")
BEGIN
  DEFINE _x _xsetbu
  DEFINE _y _top
  INCLUDE _bu_tsset

  TEXT     tx_prefix       _lft      25        _vnwd     .,		///
  		label("Prefix:")
  EDIT     ed_prefix       @         _ss       @         .,		///
  		label("Prefix")
  SPINNER  sp_step         _lft2     @         _spwd     .,		///
		option(step) min(1) max(500) default(1)			///
		label("Periods to be forecast")
  TEXT     tx_step         _spsep    @         _spr2     .,		///
		label("Periods to be forecast")



  GROUPBOX gb_dynamic      _lft      +35       _cwd1     _ht8h,		///
		label("Dynamic forecasts")
  DEFINE holdy @y
  RADIO    rb_dyndefault   _ilft     _ms       _inwd     ., first	///
		onclickon(script dyn_off)				///
		label("Begin after last observation")
  RADIO    rb_dynamic      @         _ss       @         ., last	///
		onclickon(script dyn_on)				///
		label("Begin dynamic forecasts after:")
  EDIT	   ed_dynamic      _indent2  _ss       _en14wd   .,		///
		option(dynamic)						///
  		label("Begin dynamic forecasts after")
  TEXT     tx_dynamic      @         _ss       _cwd6     .,		///
		label("(e.g., q(1979q3) or d(2jan1983))")

  GROUPBOX  gb_est         _lft2     holdy     _cwd1     _ht8h,		///
  		label("Estimation results")
  RADIO     rb_estdef      _ilft2    _ms       _cwd3     ., first	///
		onclickon(gaction main.cb_estimates.disable)		///
		label("Use active results")
  RADIO     rb_estimates   @         _ss       @         ., last	///
		onclickon(gaction main.cb_estimates.enable)		///
		label("Use alternative results:")
  COMBOBOX  cb_estimates   _indent2  _ss       _vnwd     ., dropdown	///
		option(estimates) contents(estimates) 			///
		label("Alternative results")

  CHECKBOX  ck_replace     _lft      +65       _iwd      ., 		///
  		option(replace)						///
  		label("Replace forecast variables that use a matching prefix")

  CHECKBOX  ck_diff        _lft      _ms       @         ., 		///
  		option(differences)					///
  		label("Save dynamic predictions of first-differenced variables instead of levels")
  TEXT      tx_note        _indent2  _vss      _inwd     .,		///
  		label("(Only valid after VEC estimation results)")
END

SCRIPT dyn_on
BEGIN
	main.ed_dynamic.enable
	main.tx_dynamic.enable
END

SCRIPT dyn_off
BEGIN
	main.ed_dynamic.disable
	main.tx_dynamic.disable
END

DIALOG std_err, tabtitle("Std. Errors")
BEGIN
  RADIO    rb_asymptot       _lft      _top      _iwd      ., first	///
		clickon(program bootstrap_off)				///
		option(NONE) label("Asymptotic standard errors (default)")
  RADIO    rb_nose           @         _ss       @         .,		///
		clickon(program bootstrap_off)				///
		option(nose) label("Suppress asymptotic standard errors")
  RADIO    rb_bs             @         _ss       @         .,		///
		clickon(program bootstrap_on)				///
		option(bs) label("Obtain std. errors from bootstrapped residuals (only valid after VAR or SVAR)")
  RADIO    rb_bsp            @         _ss       @         ., last	///
		clickon(program bootstrap_on)				///
		option(bsp) label("Obtain std. errors from parametric bootstrap (only valid after VAR or SVAR)")

  GROUPBOX gb_bootstrap      _lft      _ms       _iwd      _ht16,	///
		label("Bootstrap options")
  CHECKBOX ck_bscentile      _ilft     _ss       _ibwd     .,		///
		option(bscentile)					///
		label("Estimate bounds using centiles of bootstrapped dataset")

  SPINNER  sp_reps           @         _ls       _spwd     .,		///
		option(reps)						///
		min(50) default(200) max(100000)			///
		label("Number of bootstrap replications")
  TEXT     tx_reps           _spsep    @         _sprb     .,		///
		label("Number of bootstrap replications")

  CHECKBOX ck_nodots         _ilft     _ls       _ibwd     .,		///
		option(nodots)						///
		label(`"Do not display a "." for each bootstrap replication"')
  CHECKBOX ck_saving         @         _ls       @         _ht4,	///
		clickon(script saving_on)				///
		clickoff(script saving_off)				///
		label("Save bootstrap replications") groupbox
  TEXT     tx_saving         _indent   _ss       _inwd     .,		///
  		label("Filename:")
  FILE     fi_saving         @         _ss       @         ., save	///
		label("Browse...")					///
		filter("Stata Dataset (*.dta)|*.dta|All Files (*.*)|*.*") ///
		defext(dta)						///
		error("Filename for saving replications")
END

SCRIPT saving_on
BEGIN
	std_err.fi_saving.enable
	std_err.tx_saving.enable
END

SCRIPT saving_off
BEGIN
	std_err.fi_saving.disable
	std_err.tx_saving.disable
END
PROGRAM bootstrap_on
BEGIN
	call gaction std_err.gb_bootstrap.enable
	call gaction std_err.sp_reps.enable
	call gaction std_err.tx_reps.enable
	call gaction std_err.ck_nodots.enable
	call gaction std_err.ck_bscentile.enable
	call gaction std_err.ck_saving.enable
	if std_err.ck_saving {
		call script saving_on
	}
END

PROGRAM bootstrap_off
BEGIN
	call gaction std_err.gb_bootstrap.disable
	call gaction std_err.sp_reps.disable
	call gaction std_err.tx_reps.disable
	call gaction std_err.ck_nodots.disable
	call gaction std_err.ck_bscentile.disable
	call gaction std_err.ck_saving.disable
	call script saving_off
END

PROGRAM std_err_output
BEGIN
	option radio(std_err rb_asymptot rb_bs rb_nose rb_bsp)
	option std_err.ck_bscentile
	optionarg /hidedefault std_err.sp_reps
	option std_err.ck_nodots
	if (!H(std_err.ck_saving)&(std_err.ck_saving)) {
		require std_err.fi_saving
		repfile std_err.fi_saving
		put "saving("
		put `"""'
		put std_err.fi_saving
		put `"""'
		put ", replace)"
	}
END

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

PROGRAM command
BEGIN
	require main.ed_prefix
	put "fcast compute " main.ed_prefix
	beginoptions
		optionarg /hidedefault main.sp_step
		if main.rb_dynamic {
			require main.ed_dynamic
			optionarg main.ed_dynamic
		}
		if main.rb_estimates {
			require main.cb_estimates
			optionarg main.cb_estimates
		}
		option main.ck_replace
		option main.ck_diff
		put " " /program std_err_output
		optionarg /hidedefault rpt.sp_level
	endoptions
END
