/*
  expoisson.dlg

*!  VERSION 1.0.4  09jun2009

*/

VERSION 10.0

INCLUDE _std_large
DEFINE _dlght 330
INCLUDE header

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

SCRIPT PREINIT
BEGIN
	script se_createAsInternalML
	script weights_setLayout_f
END

DIALOG main, label("expoisson - Exact Poisson regression")	///
	tabtitle("Model")
BEGIN
  INCLUDE _dviv

  TEXT tx_condv		_vlx	_ls	_vlwd	.,		///
	label("Independent variables: (do not report coefficients):")
  VARLIST vl_condv	@	_ss	@	.,		///
	label("Independent variables: (do not report coefficients)")				///
	option(condvars)

  CHECKBOX ck_group	_lft	_ls	_iwd	_ht4,		///
	groupbox						///
	onclickon(script group_on)				///
	onclickoff(script group_off)				///
	label("Data are stratified by groups with their own intercepts")
  TEXT tx_group		_ilft	_ss	_ibwd	.,		///
	label("Group variable: (condition on intercepts for each value of the variable)")
  VARNAME vn_group	@	_ss	_vnwd	.,		///
	option(group)						///
	label("Group variable (condition on intercepts for each value of the variable)")

  GROUPBOX gb_opt	_lft	_xls	_iwd	_ht5,		///
	label("Options")

  RADIO rb_expose	_ilft	_ms	_cwd3_2	.,		///
	label("Exposure variable:")				///
	first							///
	onclickon(script expose)
  RADIO rb_offset	_lft3_2	@	@	.,		///
	label("Offset variable:")				///
	last							///
	onclickon(script offset)

  VARNAME vn_expose	_ilft	_ss	@	.,		///
	label("Exposure variable")				///
	option(exposure)
  VARNAME vn_offset	_lft3_2	@	@	.,		///
	label("Offset variable")				///
	option(offset)
END

SCRIPT group_on
BEGIN
	main.tx_group.enable
	main.vn_group.enable
END

SCRIPT group_off
BEGIN
	main.tx_group.disable
	main.vn_group.disable
END

SCRIPT expose
BEGIN
	main.vn_expose.enable
	main.vn_offset.disable
END

SCRIPT offset
BEGIN
	main.vn_expose.disable
	main.vn_offset.enable
END

INCLUDE byifin
INCLUDE weights

DIALOG opt, tabtitle("Options")
BEGIN
  SPINNER  sp_memory	_lft	_top	_spwd	.,		///
	default(25) min(1) max(2048)  
  TEXT     tx_mb	_spsep	@	250 	.,		///
  	label("Limit for memory usage in megabytes")
 
  CHECKBOX ck_save	_lft	+35	_iwd	_ht12,		///
	label("Save the conditional distribution")		///
	groupbox						///
	onclickon(script opt_save_on)				///
	onclickoff(script opt_save_off)

  TEXT     tx_sav	_indent	_ss	_ibwd	.,		///
	label("Filename: (prefix)")
  FILE     fi_sav	@	_ss	@	.,		///
	label("Browse...")					///
	option(saving)						///
	filter("Stata Dataset (*.dta)|*.dta|All (*.*)|*.*")	///
	defext(dta)						///
	save							///
	error("Filename")
  CHECKBOX ck_replace	@	_ls	@	.,		///
	option(replace)						///
	label("Overwrite files if they already exists")

  TEXTBOX  tb_note	_ilft	+35	_ibwd	_tb2,		///
	label("Note: the joint conditional distribution for each independent variable will be saved using the specified prefix.")
 
END

DIALOG rpt, tabtitle("Reporting")
BEGIN
  DEFINE _x _lft
  DEFINE _cx _spr
  DEFINE _y _top
  INCLUDE _sp_level

  GROUPBOX gb_coefopt	_lft	_ls	_iwd	_ht4,		///
  	label("Coefficient options")

  RADIO    rb_coef	_indent	_ss	_ibwd	., 		///
	first							///
	label("Report coefficients (default)") 			///
	option(NONE)
  RADIO    rb_irr	@	_ss	@	.,		///
	last							///
	label("Report incidence-rate ratios")			///
	option(irr)

  GROUPBOX gb_testopt	_lft	_xls	_iwd	_ht6,		///
  	label("Test options")
  
  RADIO    rb_suff	_indent	_ss	_ibwd	.,		///
	first							///
	option(test(suffidient))				///
	label("Report probability of observed sufficient statistic (default)")
  RADIO    rb_score	@	_ss	@	., 		///
	label("Report conditional scores test")			///
	option(test(score))
  RADIO    rb_prob	@	_ss	@ 	.,		///
	last 							///
	label("Report conditional probabilities test")		///
	option(test(probability))

  CHECKBOX ck_muev	_lft	+45	_iwd	.,		///
	onclickon(script mue_on) onclickoff(script mue_off)	///
	label("Report median unbiased estimates (MUEs) rather than CMLES")
  VARLIST vl_muev	+20	_ss	_vlwd	.,		///
	label("Report median unbiased estimates (MUEs) rather than CMLES") ///
	option(mue)
  TEXT    tx_muev	_vlsep	@	120	.,		///
	label("Variables")

  CHECKBOX ck_midp	_lft	_ls	_iwd	.,		///
	label("Use mid-p-value rule")				///
	option(midp)

  CHECKBOX ck_nolog	_lft	_ms	_iwd	.,		///
	label("Do not display enumeration log")			///
	option(nolog)
END

SCRIPT mue_on
BEGIN
	rpt.vl_muev.enable
	rpt.tx_muev.enable
END

SCRIPT mue_off
BEGIN
	rpt.vl_muev.disable
	rpt.tx_muev.disable
END

SCRIPT opt_save_on
BEGIN
	opt.fi_sav.enable
	opt.tx_sav.enable
	opt.ck_replace.enable
	opt.tb_note.enable
END

SCRIPT opt_save_off
BEGIN
	opt.fi_sav.disable
	opt.tx_sav.disable
	opt.ck_replace.disable
	opt.tb_note.disable
END

SCRIPT opt_suff_on
BEGIN
	opt.rb_suff.enable
	opt.rb_score.disable
	opt.rb_prob.disable
END

SCRIPT opt_score_on
BEGIN
	opt.rb_score.enable
	opt.rb_suff.disable
	opt.rb_prob.disable
END

SCRIPT opt_prob_on
BEGIN
	opt.rb_prob.enable
	opt.rb_suff.disable
	opt.rb_score.disable
END

PROGRAM command
BEGIN
	allowxi
	put /program by_output " "
	put "expoisson "
	varlist main.vn_dv main.vl_iv
	put " " /program ifin_output
	put " " /program weights_output
	beginoptions
		optionarg main.vl_condv
		optionarg main.vn_group
		optionarg main.vn_expose
		optionarg main.vn_offset

		if !opt.sp_memory.isdefault() {
			put "memory("
			put opt.sp_memory
			put "M)"
		}
		if opt.ck_save {
			require opt.fi_sav
			put `"saving("'
			put opt.fi_sav
			if opt.ck_replace {
				put `", replace"'
			}
			put ") "
		}

		optionarg /hidedefault rpt.sp_level
		option rpt.rb_irr
		option rpt.rb_score
		option rpt.rb_prob
		if rpt.ck_muev & !rpt.vl_muev {
			stopbox stop `"On the "Reporting" tab,"'	///
			`""Variables for reporting median unbiased estimates" must be filled in."'
		}
		optionarg rpt.vl_muev
		option rpt.ck_midp
		option rpt.ck_nolog
	endoptions
END
