/*
  xtrc

*!  VERSION 1.3.5  23aug2010

  keyword:  eclass

*/

VERSION 12.0

INCLUDE _std_large
DEFINE _dlght 330
INCLUDE header

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

SCRIPT PREINIT
BEGIN
	program parseMessage
	script se_createAsConventJknifeBstrap
END

PROGRAM parseMessage
BEGIN
	if __MESSAGE.contains("__MI__") {
		call script se_setMI_on
		call main.bu_xtset.hide
	}
	else {
		call main.bu_mi_xtset.hide
	}
END

SCRIPT POSTINIT
BEGIN
	program check_bytab
	script se_setCluster_off
	script se_setTitleSE
END

PROGRAM check_bytab
BEGIN
	if __MESSAGE.contains("__MI__") {
		call script byifin_set_by_off
	}
END

SCRIPT show_xtset
BEGIN
	create CHILD xtset
END

DIALOG main, label("xtrc - Random-coefficients regression") tabtitle("Model")
BEGIN
  BUTTON   bu_xtset	_xsetbu	_top	_setbuwd .,	///
	onpush(script show_xtset)			///
	label("Panel settings...")
  BUTTON   bu_mi_xtset  _xsetbu	_top	_setbuwd	.,		///
	onpush("view dialog mi_xtset")					///
	label("Panel settings...")

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

  TEXT tx_iv		_vlx	_topph	160	.,			///
	label("Independent variables:")
  VARLIST vl_iv		@	_ss	_vlwd	.,			///
	fv								///
	allowcat							///
	label("Independent variables")

  CHECKBOX ck_nocons	@	_ms	@	.,	///
	label("Suppress constant term")			///
	option(noconstant)

  TEXT     tx_offset	_lft	_ls	_cwd2	.,	///
	label("Offset variable: (optional)")
  VARNAME  vn_offset	@	_ss	_vnwd	.,	///
	label("Offset variable")			///
	option(offset)
END

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 _spr2b
  DEFINE _y 20
  INCLUDE _sp_level

  CHECKBOX ck_betas	_lft	_ls	_iwd	.,	///
	option(betas)					///
	label("Display group-specific best linear predictors")

  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

PROGRAM command
BEGIN
	put /program by_output " "
	put "xtrc "
	varlist main.vn_dv [main.vl_iv]
	if !main.vl_iv & main.ck_nocons {
	  stopbox stop `""Suppress constant term" is selected without independent variables."'
	}
	put " " /program ifin_output
	beginoptions
		option main.ck_nocons
		optionarg main.vn_offset
		put " " /program se_output
		optionarg /hidedefault rpt.sp_level
		option rpt.ck_betas
		INCLUDE _noomitted_pr
		INCLUDE _vsquish_pr
		INCLUDE _factor_vars_reporting_pr
		put " " rpt_bu_fmtcoefResults
	endoptions
END
