/*
    irf_create.dlg

*!  VERSION 1.0.2  09apr2007

*/

VERSION 8.0

INCLUDE _std_large
INCLUDE _ht340
INCLUDE header

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

DEFINE  stubwd 50
DEFINE  stubsep +55

DEFINE  lsplus +35

DIALOG main, tabtitle("Main") ///
	label("irf create - Obtain IRFs, dynamic-multiplier functions, and FEVDs")

BEGIN
  DEFINE _x _xsetbu
  DEFINE _y _top
  INCLUDE _bu_irfset
  DEFINE _y _ms
  INCLUDE _bu_tsset

  TEXT      tx_irfname       _lft      _top      _cwd1     .,		///
		label("Create IRF and store as name:")
  TEXT      tx_irfname2      @         _vss      @         .,		///
		label("(must first set an active IRF file)")
  EDIT      ed_irfname       @         _ss       _vnwd     .,		///
                label("Create IRF and store as name") max(15)
  CHECKBOX  ck_replace       _lft      _ms       _cwd2     .,		///
		option(replace) nomem					///
		label("Replace irf name if it already exists")

  SPINNER   sp_step          @         _ls       _spwd     .,		///
		option(step) min(1) max(500) default(8)			///
		label("Forecast horizon")
  TEXT      tx_step          _spsep    @         _spr2     .,		///
		label("Forecast horizon")

  GROUPBOX  gb_order         _lft      _ls       _iwd      _ht6h,	///
  		label("Order")
  RADIO     rb_orderdef      _ilft     _ss       _inwd    ., first	///
		onclickon(gaction main.cb_order.disable)		///
		label("Use default ordering of endogenous variables")
  RADIO     rb_order         @         _ss       @        ., last	///
		onclickon(gaction main.cb_order.enable)			///
		label("Order of endogenous variables:  (only allowed after VAR)")
  COMBOBOX  cb_order        _indent2   _ss       _inwd    ., 		///
  		dropdown append 					///
		option(order)						///
		contents(ereturn endog)					///
		label("Order of endogenous variables")

  GROUPBOX  gb_est         _lft      _xls      _iwd      _ht6h,		///
  		label("Estimation results")
  RADIO     rb_estdef      _ilft     _ss       _cwd0     ., first	///
		clickon(gaction main.cb_estimates.disable)		///
		label("Use active results")
  RADIO     rb_estimates   @         _ss       @         ., last	///
		clickon(gaction main.cb_estimates.enable)		///
		label("Use alternative results:")
  COMBOBOX  cb_estimates   _indent2  _ss       _vnwd     ., dropdown	///
		option(estimates) contents(estimates) 			///
		label("Alternative results")
END


DIALOG std_err, tabtitle("Std. errors")
BEGIN
  CHECKBOX  ck_std_err       _lft      _top      _iwd      _ht25,	///
  		groupbox						///
  		onclickon(program se_on) onclickoff(program se_off)	///
  		label("Override default standard errors (valid after VAR and SVAR only)")
  RADIO     rb_asymptot      _ilft     _ms       _inwd     ., first	///
		onclickon(program bootstrap_off)			///
		option(NONE) label("Asymptotic standard errors (default after VAR and SVAR)")
  RADIO     rb_nose          @         _ss       @         .,		///
		onclickon(program bootstrap_off)			///
		option(nose) 						///
		label("Do not calculate standard errors")
  RADIO     rb_bs            @         _ss       @         .,		///
		onclickon(program bootstrap_on)				///
		option(bs) label("Obtain standard errors from bootstrapped residuals")
  RADIO     rb_bsp           @         _ss       @         ., last	///
		onclickon(program bootstrap_on)				///
		option(bsp) label("Obtain standard errors from parametric bootstrap")

  GROUPBOX  gb_bootstrap     _ilft     _ms       _ibwd     _ht13,	///
		label("Bootstrap options")
  CHECKBOX  ck_nodots        _indent   _ss       _inwd     .,		///
		option(nodots)						///
		label(`"Do not display a "." for each bootstrap replication"')
DEFINE width @xsize
  SPINNER   sp_reps          @         _ls       _spwd     .,		///
		option(reps)						///
		min(50) default(200) max(100000)			///
		label("Number of bootstrap replications")
DEFINE x @x
  TEXT      tx_reps          _spsep    @         _cksprb   .,		///
		label("Number of bootstrap replications")
  CHECKBOX ck_saving         x         _ls       width     _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

PROGRAM se_on
BEGIN
	call std_err.rb_asymptot.enable
	call std_err.rb_bs.enable
	call std_err.rb_nose.enable
	call std_err.rb_bsp.enable
	if std_err.rb_bs | std_err.rb_bsp {
		call program bootstrap_on
	}
END

PROGRAM se_off
BEGIN
	call std_err.rb_asymptot.disable
	call std_err.rb_bs.disable
	call std_err.rb_nose.disable
	call std_err.rb_bsp.disable
	call program bootstrap_off
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 std_err.gb_bootstrap.enable
	call std_err.sp_reps.enable
	call std_err.tx_reps.enable
	call std_err.ck_nodots.enable
	call std_err.ck_saving.enable
	if std_err.ck_saving {
		call script saving_on
	}
END

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

PROGRAM command
BEGIN
	put "irf create "
	require main.ed_irfname
	put main.ed_irfname
	beginoptions
		option main.ck_replace
		optionarg /hidedefault main.sp_step
		// not including set() option since we have an
		//    IRF set button at top
		if main.rb_order {
			require main.cb_order
			optionarg main.cb_order
		}
		if main.rb_estimates {
			require main.cb_estimates
			optionarg main.cb_estimates
		}
		option std_err.rb_nose
		option std_err.rb_bs
		option std_err.rb_bsp
		option std_err.ck_nodots
		optionarg /hidedefault std_err.sp_reps
		if std_err.ck_saving & !D(std_err.ck_saving) {
			require std_err.fi_saving
			repfile std_err.fi_saving
			put "bsaving("
			put `"""'
			put std_err.fi_saving
			put `"""'
			put ", replace"
			put ")"
		}
	endoptions
END
