/*
  cnsreg

*!  VERSION 1.2.9  21jan2011

  keyword:  eclass

*/

VERSION 12.0

INCLUDE _std_large
DEFINE _dlght 330
INCLUDE header
HELP hlp1, view("help cnsreg")
RESET res1

SCRIPT PREINIT
BEGIN
	program parseMessage
	script se_createAsSvyOLS
	program svy_check_title
END

PROGRAM parseMessage
BEGIN
	if __MESSAGE.contains("__MI__") {
		call script se_setMI_on
	}
END

SCRIPT POSTINIT
BEGIN
	program check_bytab
	program se_setFinalInitState
	script _constraints_main_setRequiredOn
END

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

SCRIPT svy_is_on
BEGIN
	//
END
SCRIPT svy_is_off
BEGIN
	//
END
PROGRAM svy_check_title
BEGIN
	if __MESSAGE.contains("-svy-") {
		call settitle "svy: cnsreg - Constrained linear regression for survey data"
	}
END

DIALOG main, tabtitle("Model")						///
	title("cnsreg - Constrained linear regression")	// has svy title
BEGIN
  TEXT tx_dv 		_lft	_top	_vnwd	.,			///
	label("Dependent variable:")
  VARNAME vn_dv		@ 	_ss	@	.,			///
	ts								///
	label("Dependent variable")

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

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

  DEFINE _x _lft
  DEFINE _xw _ibwd
  INCLUDE _ck_collinear
END

INCLUDE _constraints_sc
INCLUDE sub_by_ifin_over_subpop
INCLUDE weights_fpai
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 _spr
  DEFINE _y 20
  INCLUDE _sp_level

  DEFINE _x _lft
  DEFINE _y _ls
  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

PROGRAM command
BEGIN
	put /program by_output " "
	put /program se_prefix_output " "
	put "cnsreg "
	varlist main.vn_dv main.vl_iv
	put " " /program ifin_output
	put " " /program weights_output
	beginoptions
		require main.cb_constr
		INCLUDE _constraints_main_pr
		option main.ck_collinear
		option main.ck_nocon
		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
	endoptions
END
