/*
  newey

*! VERSION 1.0.6  23aug2010

  keyword:  eclass

*/

VERSION 12.0

INCLUDE _std_large
INCLUDE header

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

DIALOG main, label("newey - Regression with Newey-West standard errors")/*
		*/ tabtitle("Model")
BEGIN
  /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+*/ 
  DEFINE _x _xsetbu
  DEFINE _y _top
  INCLUDE _bu_tsset

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

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

  CHECKBOX ck_nocons @         _ms       @         .,			/*
		*/ label("Suppress constant term")			/*
		*/ option("noconstant")					/*
		*/  
  GROUPBOX gb_lag    _lft      _ls       _iwd      _ht5,		/*
  		*/ label("")
  RADIO    rb_lag0   _ilft     _ss       _inwd     .,			/*
		*/ label("No autocorrelation structure")		/*
		*/ clickon("script lag0")				/*
		*/ first						/*
		*/ option("lag(0)")					/*
		*/
  RADIO    rb_lag    @         _ms       _rbwd     .,			/*
		*/ clickon("script lag")				/*
		*/ last							/*
		*/
  SPINNER  sp_lag    _rbsep    @         _spwd     .,			/*
		*/ label("Maximum lag")					/*
		*/ min(1)						/*
		*/ max(c(N))						/*
		*/ default("1")						/*
		*/ option("lag")					/*
		*/
  DEFINE x @x
  TEXT     tx_lag    _spsep    @         _rbsprb   .,			/*
*/ label("Maximum lag to consider in the autocorrelation structure")	/*
		*/
		
END

SCRIPT lag0
BEGIN
	main.sp_lag.disable
END

SCRIPT lag
BEGIN
	main.sp_lag.enable
END

INCLUDE byifin
INCLUDE weights_a

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

  DEFINE _x _lft
  DEFINE _y _ls
  DEFINE _cx _iwd
  INCLUDE _noomitted

  DEFINE _x _lft
  DEFINE _y _ms
  DEFINE _cx _iwd
  INCLUDE _vsquish

  DEFINE _x _lft
  DEFINE _y _ls
  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 rpt_output
BEGIN
	optionarg /hidedefault rpt.sp_level
	INCLUDE _noomitted_pr
	INCLUDE _vsquish_pr
	INCLUDE _factor_vars_reporting_pr
	put " " rpt_bu_fmtcoefResults
END

PROGRAM command
BEGIN
	put " " /program by_output
	put "newey "
	varlist main.vn_dv [main.vl_iv]
	if !main.vl_iv & main.ck_nocons {
	  stopbox stop `""Suppress constant term" is selected without independent variables."'
	} 	
	INCLUDE _weights_pr
	put " " /program ifin_output
	beginoptions
		option main.ck_nocons
		option main.rb_lag0
		if main.rb_lag {
			optionarg main.sp_lag
		}		
		put " " /program rpt_output
	endoptions
END

