/*
	cusum

*!  VERSION 2.0.1  07mar2011

*/

VERSION 12.0

INCLUDE _std_large
DEFINE _dlght 300
INCLUDE header

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

DIALOG main, label("cusum - Cusum plots and tests for binary variables") tabtitle("Main")
BEGIN
  TEXT     tx_yvar	_lft	_top	_vnwd	.,	///
	label("Y variable:")
  VARNAME  vn_yvar	@	_ss	_vnwd	., 	///
	label("Y variable")

  TEXT     tx_xvar	+150	_top	_vnwd	.,	///
	label("X variable:")
  VARNAME  vn_xvar	@	_ss	_vnwd	.,	///
	label("X variable")

  CHECKBOX ck_gen	_lft	+35	_iwd	.,	///
	label("Save cumulative sum in dataset")		///
	onclickon(script generate_on)			///
	onclickoff(script generate_off)
  EDIT     ed_gen	_indent2 _ss	_vnwd	.,	///
	option(generate)				///
	label("New variable name")
  TEXT     tx_gen	_vnsep	@	150	.,	///
	label("New variable name")

  CHECKBOX ck_yfit	_lft	_ls	_iwd	.,	///
	label("Calculate cumulative sum against variable") ///
	onclickon(script yfit_on)			///
	onclickoff(script yfit_off)
  VARNAME  vn_yfit	_indent2 _ss	_vnwd	.,	///
	option(yfit) 					///
	label("Calculate cumulative sum against variable")
  TEXT     tx_yfit	_vnsep	@	150	.,	///
	label("Variable")

  CHECKBOX ck_nograph	_lft	_ls	_iwd	.,	///
	option(nograph) label("Suppress the plot")	///
	onclickoff(script graph_on) 			///
	onclickon(script graph_off)
  CHECKBOX ck_nocalc	@	_ms	@	.,	///
	option(nocalc) label("Suppress cusum test statistics")
END

SCRIPT generate_on
BEGIN
	main.ed_gen.enable
	main.tx_gen.enable
END

SCRIPT generate_off
BEGIN
	main.ed_gen.disable
	main.tx_gen.disable
END

SCRIPT yfit_on
BEGIN
	main.vn_yfit.enable
	main.tx_yfit.enable
END

SCRIPT yfit_off
BEGIN
	main.vn_yfit.disable
	main.tx_yfit.disable
END


SCRIPT graph_on
BEGIN
	/* turn on all the graphs tabs */
	script gr_plots_enable
	script gr_addplots_enable
	script gr_yaxis_enable
	script gr_xaxis_enable
	script gr_titles_enable
	script gr_legend_enable
	script gr_overall_enable
END

SCRIPT graph_off
BEGIN
	/* turn off all the graphs tabs */
	script gr_plots_disable
	script gr_addplots_disable
	script gr_yaxis_disable
	script gr_xaxis_disable
	script gr_titles_disable
	script gr_legend_disable
	script gr_overall_disable
END

INCLUDE ifin
INCLUDE gr_plots
INCLUDE gr_addplots
INCLUDE gr_yaxis
INCLUDE gr_xaxis
INCLUDE gr_titles
INCLUDE gr_legend
INCLUDE gr_overall

SCRIPT POSTINIT
BEGIN
	gr_plots.settabtitle "Cusum plot"
	script gr_plots_setDefaultLine
END

PROGRAM command
BEGIN
	put "cusum "
	require main.vn_xvar
	varlist main.vn_yvar
	varlist main.vn_xvar
	INCLUDE _ifin_pr
	beginoptions
		if main.ck_gen {
			require main.ed_gen
			optionarg main.ed_gen
		}
		if main.ck_yfit {
			require main.vn_yfit
			optionarg main.vn_yfit
		}
		option main.ck_nograph
		option main.ck_nocalc

		put " " /program gr_plots_output
		put " " /program gr_addplots_output
		put " " /program gr_yaxis_output
		put " " /program gr_xaxis_output
		put " " /program gr_titles_output
		put " " /program gr_legend_output
		put " " /program gr_overall_output
	endoptions
END
