/*
	predict (after xtnbreg, re|fe)

*!  VERSION 2.0.1  27may2010

*/

VERSION 11.0

INCLUDE _std_medium
DEFINE _dlght 290
INCLUDE header

HELP hlp1, view("help xtnbreg postestimation")
RESET res1

PROGRAM POSTINIT_PROGRAM
BEGIN
	call create STRING isRE
	call isRE.setvalue e(model)

	if(isRE.iseq("re")) {
		call script main_pr0_show
	}
	else {
		call script main_pr0_hide
	}
END

DIALOG main, label("predict - Prediction after estimation") tabtitle("Main")
BEGIN
  INCLUDE  _p_gentype

  GROUPBOX gb_opts           _lft      _ls       _iwd      _ht8,	/*
		*/ label("Produce:")
  RADIO    rb_xb             _indent   _ss       _inwd     ., first	/*
		*/ option(xb)						/*
		*/ label("Linear prediction")
  RADIO    rb_stdp           @         _ss       @         .,		/*
		*/ option(stdp)						/*
		*/ label("Standard error of the linear prediction")
  RADIO    rb_nu0            @         _ss       @         .,		/*
		*/ option(nu0)						/*
		*/ label("Number of events assuming u_i = 0")
  RADIO    rb_iru0           @         _ss       @         .,		/*
		*/ option(iru0)						/*
		*/ label("Incidence rate assuming u_i = 0")
  RADIO    rb_pr_n           @         _ss       @         .,		/*
		*/ onclickon(script main_pr_n_on)			/*
		*/ onclickoff(script main_pr_n_off)			/*
		*/ label("Probability of y=n")
  RADIO    rb_pr_a_b       @         +45       @         ., last	/*
		*/ onclickon(script main_pr_a_b_on)			/*
		*/ onclickoff(script main_pr_a_b_off)			/*
		*/ label("Probability of a<=y<=b")

  EDIT      ed_pr_n          _indent2  -20      _en7wd    .,		/*
		*/ option(pr0)						/*
		*/ label("Probability of y=n")
DEFINE x @x
  TEXT      tx_pr_n          _en7sep   @         50        .,		/*
		*/ label("n")

  EDIT      ed_pr_a         x         +45       _en7wd    .,		/*
		*/ label("Probability of a<=y")
  TEXT      tx_pr_a         _en7sep   @         50        .,		/*
		*/ label("a")

  EDIT      ed_pr_b         +55       @        _en7wd     .,		/*
		*/ label("Probability of y<=b")
  TEXT      tx_pr_b         _en7sep   @        50         .,		/*
		*/ label("b")

  CHECKBOX ck_nooffset       _lft      +100     _iwd       .,		/*
		*/ option(nooffset)					/*
		*/ label("Ignore offset variable (if any)")
END
                
SCRIPT main_pr0_show
BEGIN
	main.rb_pr_n.show
	main.rb_pr_a_b.show
	main.ed_pr_n.show
	main.tx_pr_n.show
	main.ed_pr_a.show
	main.tx_pr_a.show
	main.ed_pr_b.show
	main.tx_pr_b.show
	main.gb_opts.setposition		. . . 200
	main.ck_nooffset.setposition		. 265 . .
END

SCRIPT main_pr0_hide
BEGIN
	main.rb_pr_n.hide
	main.rb_pr_a_b.hide
	main.ed_pr_n.hide
	main.tx_pr_n.hide
	main.ed_pr_a.hide
	main.tx_pr_a.hide
	main.ed_pr_b.hide
	main.tx_pr_b.hide
	main.gb_opts.setposition		. . . 105
	main.ck_nooffset.setposition		. 175 . .
END

SCRIPT main_pr_n_on
BEGIN
	script _p_gentype_score_off
	main.ed_pr_n.enable
	main.tx_pr_n.enable
END

SCRIPT main_pr_n_off
BEGIN
	script _p_gentype_score_off
	main.ed_pr_n.disable
	main.tx_pr_n.disable
END

SCRIPT main_pr_a_b_on
BEGIN
	script _p_gentype_score_off
	main.ed_pr_a.enable
	main.tx_pr_a.enable
	main.ed_pr_b.enable
	main.tx_pr_b.enable
END

SCRIPT main_pr_a_b_off
BEGIN
	script _p_gentype_score_off
	main.ed_pr_a.disable
	main.tx_pr_a.disable
	main.ed_pr_b.disable
	main.tx_pr_b.disable
END

INCLUDE _p_gentype_sc
INCLUDE ifin
INCLUDE _type_list_fd

PROGRAM main_ed_pr_a_b_output
BEGIN
	put "pr0("
	put main.ed_pr_a
	put ","
	put main.ed_pr_b
	put ")"
END

PROGRAM command
BEGIN
	put "predict "
	put " " /program _p_gentype_output
	INCLUDE _ifin_pr
	beginoptions
		option radio(main rb_xb rb_stdp rb_nu0 rb_iru0)
		if main.rb_pr_n {
			require main.ed_pr_n
			optionarg main.ed_pr_n
		}
		if main.rb_pr_a_b {
			require main.ed_pr_a
			require main.ed_pr_b
			put " " /program main_ed_pr_a_b_output
		}
		option main.ck_nooffset
	endoptions
END
