/*
	xtmixed_mle_eq.dlg

*! VERSION 1.0.0  07jun2011

*/

VERSION 12.0

INCLUDE _std_small
DEFINE _dlght 350
INCLUDE header

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

SCRIPT PREINIT
BEGIN
	create STRING parent_name
	create STRING FWeightStr
	create STRING PWeightStr
	create DOUBLE allow_fweight
	create DOUBLE allow_pweight
	create DOUBLE childDLGNum

	parent_name.setvalue class PARENT._dlg_rsrcname
	parent_name.withvalue allow_fweight.setvalue			///
		class @.allow_fweights.value
	parent_name.withvalue allow_pweight.setvalue			///
		class @.allow_pweights.value
	parent_name.withvalue childDLGNum.setvalue			///
		class @.main_mle_childDLGNum.value
	childDLGNum.withvalue FWeightStr.setvalue "allow_fweights_eq@"
	childDLGNum withvalue PWeightStr.setvalue "allow_pweights_eq@"
END

PROGRAM POSTINIT_PROGRAM
BEGIN
	if allow_fweight {
		call main.ck_fweight.enable
	}
	else {
		call main.ck_fweight.disable
	}

	if allow_pweight {
		call main.ck_pweight.enable
	}
	else {
		call main.ck_pweight.disable
	}
END

DIALOG main, label("")
BEGIN
  TEXT tx_level			_lft	_top	_iwd	.,		///
	label("Level variable for equation")
  VARNAME  vn_level		@	_ss	_vnwd	.,		///
	label("Level variable for equation")
  RADIO rb_independent		@	_ls	_iwd	., first	///
	onclickon(script main_independent_on)				///
	label("Independent variables for equation")
  RADIO rb_factor		@	_ss	@	., last		///
	onclickon(script main_factor_on)				///
	label("Factor variable for equation")
  VARLIST vl_independent	_indent2 _ms	_inwd	.,		///
	ts								///
	label("Independent variables for equation")
  VARNAME vn_factor		@	@	_vnwd	.,		///
	label("Factor variable for equation")

  TEXT tx_cov_structure		@	_ls	_iwd	.,		///
	label("Variance-covariance structure of the random effects")
  COMBOBOX cb_cov_structure	@	_ss	_vnwd	.,		///
	option(covariance)						///
	dropdownlist							///
	contents(main_covariance_list)
  COMBOBOX cb_fcov_structure	@	@	@	.,		///
	option(covariance)						///
	dropdownlist							///
	contents(main_covariance_2_list)
  CHECKBOX ck_noconstant	_lft	_ls	_iwd	.,		///
	option(noconstant)						///
	label("Suppress constant term from the random-effects equation")
  CHECKBOX ck_collinear		@	_ms	@	.,		///
	option(collinear)						///
	label("Keep collinear variables")
  CHECKBOX ck_fweight		@	_ls	_iwd	.,		///
	onclickon(script main_fweight_on)				///
	onclickoff(program main_fweight_off)				///
	label("Frequency weights:")
  EXP ex_fweight		_indent2 _ss	_inwd	.,		///
	option(fweight)							///
	error("Frequency weights")					///
	label("Create...")

  CHECKBOX ck_pweight		_lft	_ls	_iwd	.,		///
	onclickon(script main_pweight_on)				///
	onclickoff(program main_pweight_off)				///
	label("Sampling weights:")
  EXP ex_pweight		_indent2 _ss	_inwd	.,		///
	option(pweight)							///
	error("Sampling weights")					///
	label("Create...")
END

LIST main_covariance_list
BEGIN
	independent
	exchangeable
	identity
	unstructured
END

LIST main_covariance_2_list
BEGIN
	identity
	exchangeable
END

SCRIPT main_independent_on
BEGIN
	main.vl_independent.show
	main.vn_factor.hide
	main.cb_cov_structure.show
	main.cb_fcov_structure.hide

END

SCRIPT main_factor_on
BEGIN
	main.vl_independent.hide
	main.vn_factor.show
	main.cb_cov_structure.hide
	main.cb_fcov_structure.show
END

SCRIPT main_fweight_on
BEGIN
	main.ex_fweight.enable
	main.ck_pweight.disable
END

PROGRAM main_fweight_off
BEGIN
	call main.ex_fweight.disable
	if allow_pweight {
		call main.ck_pweight.enable
	}
END

SCRIPT main_pweight_on
BEGIN
	main.ex_pweight.enable
	main.ck_fweight.disable
END

PROGRAM main_pweight_off
BEGIN
	call main.ex_pweight.disable
	if allow_fweight {
		call main.ck_fweight.enable
	}
END

PROGRAM command
BEGIN
	put " " "|| "
	require main.vn_level
	put main.vn_level ": "
	if main.rb_independent {
		varlist [main.vl_independent]
		beginoptions
			option main.ck_noconstant
			optionarg main.cb_cov_structure
		endoptions
	}
	if main.rb_factor {
		require main.vn_factor
		put "R."
		put main.vn_factor
		beginoptions
			optionarg main.cb_fcov_structure
		endoptions
	}
	beginoptions
		option main.ck_collinear
		if main.ck_fweight & main.ck_fweight.isenabled() {
			require main.ex_fweight
			optionarg main.ex_fweight
			call FWeightStr.withvalue PARENT.callthru "@.settrue"
			call PWeightStr.withvalue PARENT.callthru "@.setfalse"
		}
		if main.ck_pweight & main.ck_pweight.isenabled() {
			require  main.ex_pweight
			optionarg main.ex_pweight
			call FWeightStr.withvalue PARENT.callthru "@.setfalse"
			call PWeightStr.withvalue PARENT.callthru "@.settrue"
		}
		if !main.ck_fweight & !main.ck_pweight {
			call FWeightStr.withvalue PARENT.callthru "@.settrue"
			call PWeightStr.withvalue PARENT.callthru "@.settrue"
		}
	endoptions
END
