/*
  stsplit INCLUDE file

*!  VERSION 1.0.0  29may2009

*/

  DEFINE   _x _xsetbu
  DEFINE   _y _top
  INCLUDE _bu_stset

  GROUPBOX gb_type		_lft	_ss	_iwd	_ht6,	///
	label("Type")

  RADIO    rb_designated	_indent	_ss	_cwd1	.,	///
  	first 							///
  	onclickon(script designated_syntax)			///
  	label("Split at designated times")
  RADIO    rb_failure		@	_ss	@	.,	///
  	onclickon(script failure_syntax)			///
  	label("Split at failure times")
  RADIO    rb_join		@	_ss	@	.,	///
  	last 							///
  	onclickon(script join_syntax)				///
  	label("Join episodes")

//
  GROUPBOX gb_newvar		_lft	_xls	_iwd	50,	///
  	label("Variable to record time interval to which each new observation belongs")
  EDIT     ed_newvar		_ilft	_ss	_vnwd	.,	///
  	error("New variable name")
  TEXT     tx_newvar		_vnsep	@	@	.,	///
  	label("New variable name")

//
  GROUPBOX gb_analysis_time	_lft	190	_iwd	120,	///
  	label("Analysis times at which the records are to be split")

  RADIO    rb_at		_ilft	_ss	_ibwd	.,	///
  	first	onclickon(script at_on)				///
  	label("Split records at specified analysis times")
  RADIO	   rb_every		@	+50	_ibwd	.,	///
  	last	onclickon(script every_on)			///
  	label("Split records at each positive multiple of a number")

  EDIT     ed_at1		+20	-30	_vnwd	.,	///
  	label("Analysis time")					///
  	option(at)
  DEFINE x @x
  TEXT     tx_at1		_vnsep	@	@	.,	///
  	label("Analysis time")

  SPINNER  sp_every		x	+50	_spwd	.,	///
  	min(1) max(1000000) default(1)				///
  	option(every)
  TEXT     tx_every		_spsep	@	@	.,	///
  	label("Number")

//
  GROUPBOX gb_options		_lft	320	_iwd	75,	///
  	label("Options")

  EDIT     ed_after		_indent	_ss	_vlwd	.,	///
  	label("Reference time")					///
  	option(after)
  DEFINE x @x
  TEXT     tx_after		_vlsep	@	100	.,	///
  	label("Reference time")

  CHECKBOX ck_trim		x	_ls	_cwd0	.,	///
	label("Exclude observations outside of range")  	///
	option(trim)

  TEXT     tx_strata		_ilft	155	_vlwd	.,	///
  	label("Strata variables: (limit 5)")
  VARLIST  vl_strata		@	_ss	@	.,	///
  	option(strata)	label("Strata variables")
  TEXT     tx_riskset		@	_ls	@	.,	///
  	label("Name of new variable recording unique risk set:")
  EDIT     ed_riskset		@	_ss	_vnwd	.,	///
  	option(riskset)

////
  TEXT     tx_censored		_ilft	155	_ibwd	.,	///
  	label("Values of failure variable:")
  EDIT     ed_censored		@	_ss	_vnwd	.,	///
  	option(censored)
END

SCRIPT at_on
BEGIN
	main.ed_at1.enable
	main.tx_at1.enable
	main.ck_trim.enable
	main.sp_every.disable
	main.tx_every.disable
END

SCRIPT every_on
BEGIN
	main.ed_at1.disable
	main.tx_at1.disable
	main.ck_trim.disable
	main.sp_every.enable
	main.tx_every.enable
END

SCRIPT designated_syntax
BEGIN
	main.tx_strata.hide
	main.vl_strata.hide
	main.tx_riskset.hide
	main.ed_riskset.hide
	main.tx_censored.hide
	main.ed_censored.hide

	main.gb_newvar.show
	main.ed_newvar.show
	main.tx_newvar.show
	main.gb_analysis_time.show
	main.gb_analysis_time.setposition . 190 . 120
	main.rb_at.show
	main.rb_every.show
	main.ed_at1.show
	main.tx_at1.show
	main.sp_every.show
	main.tx_every.show
	main.gb_options.setposition . 320 . 75
	main.ed_after.show
	main.tx_after.show
	main.ck_trim.show
	script if_enable
END

SCRIPT failure_syntax
BEGIN
	main.gb_newvar.hide
	main.ed_newvar.hide
	main.tx_newvar.hide
	main.rb_at.hide
	main.rb_every.hide
	main.ed_at1.hide
	main.tx_at1.hide
	main.sp_every.hide
	main.tx_every.hide
	main.ed_after.hide
	main.tx_after.hide
	main.ck_trim.hide
	main.tx_censored.hide
	main.ed_censored.hide
	main.gb_analysis_time.hide

	main.gb_options.setposition . 135 . 120
	main.tx_strata.show
	main.vl_strata.show
	main.tx_riskset.show
	main.ed_riskset.show
	script if_enable
END

SCRIPT join_syntax
BEGIN
	main.gb_newvar.hide
	main.ed_newvar.hide
	main.tx_newvar.hide
	main.rb_at.hide
	main.rb_every.hide
	main.ed_at1.hide
	main.tx_at1.hide
	main.sp_every.hide
	main.tx_every.hide
	main.ed_after.hide
	main.tx_after.hide
	main.ck_trim.hide
	main.tx_strata.hide
	main.vl_strata.hide
	main.tx_riskset.hide
	main.ed_riskset.hide
	main.gb_analysis_time.hide

	main.gb_options.setposition . 130 . 75
	main.tx_censored.show
	main.ed_censored.show
	script if_disable
END

INCLUDE if

PROGRAM command
BEGIN
	if main.rb_designated | main.rb_failure {
		if isMI {
			put "mi "	
		}
		put "stsplit "
		// designated syntax
		require main.ed_newvar
		put main.ed_newvar " "
		INCLUDE _if_pr
		beginoptions
			// designated syntax
			require main.ed_at1
			optionarg main.ed_at1
			optionarg main.sp_every
			optionarg main.ed_after
			option main.ck_trim
			// failure syntax
			if main.rb_failure {
				put "at(failure) "
			}
			optionarg main.vl_strata
			optionarg main.ed_riskset
		endoptions
	}
	if main.rb_join {
		// stjoin syntax
		if isMI {
			put "mi "	
		}
		put "stjoin "
		beginoptions
			optionarg main.ed_censored
		endoptions
	}
END
