/*
  arfima

*!  VERSION 1.0.2  20jun2011

*/

VERSION 12.0

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

SCRIPT main_PREINIT
BEGIN
	script _constraints_main_setOptionalOn
	script se_createAsRobustOIM
END

SCRIPT main_POSTINIT
BEGIN
	script max_enableGTolerance
END

DIALOG main, tabtitle("Model")	///
	label("arfima - ARFIMA, autoregressive fractionally integrated moving-average models")
BEGIN
  DEFINE _x _xsetbu
  DEFINE _y _top
  INCLUDE _bu_tsset

  TEXT tx_dv 			_lft	_topph	_vnwd	.,		///
	label("Dependent variable:")
  VARNAME vn_dv			@ 	_ss	@	.,		///
	ts								///
	label("Dependent variable")

  TEXT tx_iv			_vlx	_topph	160	.,		///
	label("Independent variables:")
  VARLIST vl_iv			@	_ss	_vlwd	.,		///
	fv ts								///
	allowcat							///
	label("Independent variables")
  CHECKBOX ck_nocons		@	_ms	@	.,		///
	option(noconstant)						///
	label("Suppress constant term")

  CHECKBOX ck_arma		_lft	_ls	_iwd	_ht4,		///
	groupbox							///
	onclickon("script main_arma_on")				///
	onclickoff("script main_arma_off")				///
	label(`"Supply list of ARMA lags: (e.g., "1 3")"')

  TEXT tx_ar			_indent	_ss	_en14wd	.,		///
	label("List of AR lags")
  DEFINE holdy @y
  EDIT ed_ar			@	_ss	@	.,		///
	option("ar")							///
	label("List of AR lags")
  TEXT tx_ma			_lft2	holdy	_en14wd	.,		///
	label("List of MA lags")
  EDIT ed_ma			@	_ss	@	.,		///
	option("ma")							///
	label("List of MA lags")

  CHECKBOX ck_smemory		_lft	_xxls	_iwd	.,		///
	option(smemory)							///
	label("Estimate short-memory model without fractional integration")
  CHECKBOX ck_mle		_lft	_ms	_iwd	.,		///
	option(mle)							///
	onclickon("main.ck_mpl.disable")				///
	onclickoff("main.ck_mpl.enable")				///
	label("Maximum likelihood estimates")
  CHECKBOX ck_mpl		_lft	_ms	_iwd	.,		///
	option(mpl)							///
	onclickon("main.ck_mle.disable")				///
	onclickoff("main.ck_mle.enable")				///
	label("Estimate using the modified profile likelihood")

  DEFINE _x _lft
  DEFINE _y _ls
  DEFINE _cx _lw80
  DEFINE _bux _slw80
  INCLUDE _constraints

  DEFINE _x _lft
  DEFINE _xw _iwd
  INCLUDE _ck_collinear
END

SCRIPT main_arma_on
BEGIN
	main.tx_ar.enable
	main.ed_ar.enable
	main.tx_ma.enable
	main.ed_ma.enable
END

SCRIPT main_arma_off
BEGIN
	main.tx_ar.disable
	main.ed_ar.disable
	main.tx_ma.disable
	main.ed_ma.disable
END

INCLUDE _constraints_sc
INCLUDE _arima_main_sc

INCLUDE byifin
INCLUDE se


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 _spr2
  DEFINE _y _top
  INCLUDE _sp_level

  DEFINE _x _lft
  DEFINE _y _ms
  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 _ms
  DEFINE _cx _iwd
  INCLUDE _factor_vars_reporting

  DEFINE _x _lft
  DEFINE _y _xxxls
  INCLUDE _bu_coef_table_reporting
END

INCLUDE fmt_coef_table_reporting_pr

INCLUDE max_ml

PROGRAM command
BEGIN
	allowxi
	INCLUDE _by_pr
	put "arfima "
	varlist main.vn_dv [main.vl_iv]
	INCLUDE _ifin_pr
	beginoptions
		option main.ck_nocons
		if main.ck_arma {
			if !main.ed_ar & !main.ed_ma {
				stopbox stop				///
			`"You must specify either "List of AR lags""'	///
			`" or "List of MA lags"."'
			}
			if (main.ed_ar & (!main.ed_ar.isnumlist())) {
				stopbox stop				///
			`"There is an invalid "Numlist" for "List of AR lags""'
			}
			if (main.ed_ma & (!main.ed_ma.isnumlist())) {
				stopbox stop				///
			`"There is an invalid "Numlist" for "List of MA lags""'
			}
			optionarg main.ed_ar
			optionarg main.ed_ma
		}
		option main.ck_smemory
		option main.ck_mle
		option main.ck_mpl
		INCLUDE _constraints_main_pr
		option main.ck_collinear

		put " " /program se_output
		optionarg /hidedefault rpt.sp_level
		INCLUDE _nocnsreport_pr
		INCLUDE _noomitted_pr
		INCLUDE _vsquish_pr
		INCLUDE _factor_vars_reporting_pr
		put " " rpt_bu_fmtcoefResults
		put " " /program max_output
	endoptions
END
