/* 

*! meta dialog version 1.0.1, 13 May 2003, T. J. Steichen, steichen@triad.rr.com 
*!    for meta version 2.06,     Mar 1998, Stephen Sharp, stephen.j.sharp@gsk.com
*!                                         Jonathan Sterne, jonathan.sterne@bristol.ac.uk

Fixed and random-effects meta-analysis, with graphics
-----------------------------------------------------

Syntax: meta  { theta | exp(theta) } { se_theta | var_theta | ll ul [cl] }
           [if exp] [in range] [ , id(strvar) var ci graph(f|r|e) eform print 
           ebayes level(#) fmult(#) boxysca(#) boxshad(#) cline ltrunc(#) rtrunc(#)]

To install in User Statistics menu via Stata commands:
  . window menu append item "stUserStatistics" "Meta-analysis of Effects (&meta)" "db meta"
  . window menu refresh
To permanently install, place the commands in your -profile.do- file.
*/

VERSION 8.0

INCLUDE _std_small
INCLUDE header

HELP hlp1, view("help meta")
RESET res1, label("Reset")

DIALOG main, label("meta 2.06 - Meta-analysis of Effects") tabtitle("Main")
BEGIN
  GROUPBOX gb_data      10    5  330  _ht5h,            ///
     label("Type of Data:")
  RADIO    r_se         15   25  100      .,            ///
     label("Theta, SE")        first                    ///
     onclickon(script main_se_on)                       ///
     onclickoff(script main_se_off)                     ///
     option(NONE)
  RADIO    r_var       115   25  100      .,            ///
     label("Theta, Var")       middle                   ///
     onclickon(script main_var_on)                      ///
     onclickoff(script main_var_off)                    ///
     option("var")
  RADIO    r_ci        215   25  110      .,            ///
     label("exp(Theta), CI")   last                     ///
     onclickon(script main_ci_on)                       ///
     onclickoff(script main_ci_off)                     ///
     option("ci")

  TEXT     tx_se        15   45   320     .,            ///
     label("Vars for theta, se(theta), in that order")
  VARLIST  vl_se         @   _ss   @      .,            ///
     label("Vars for theta, se(theta)")

  TEXT     tx_var        @   45   320     .,            ///
     label("Vars for theta, var(theta), in that order")
  VARLIST  vl_var        @   _ss   @      .,            ///
     label("Vars for theta, var(theta)")
  
  TEXT     tx_ci         @   45   320     .,            ///
     label("Vars for exp(theta), CI_LL, CI_UL, in that order")
  VARLIST  vl_ci         @   _ss   @      .,            ///
     label("Vars for exp(theta), CI_LL, CI_UL")

  CHECKBOX cb_id        10 100  100       .,            ///
     label("ID Variable:")                              ///
     onclickon(main.vn_id.enable)                       ///
     onclickoff(main.vn_id.disable)
  VARNAME  vn_id       110 100  230       .,            /// 
     label("ID Variable")                               ///
     option("id")

  CHECKBOX cb_eform     10 130  150       .,            ///
     label("Use exp(theta)")                            ///
     option("eform")
  CHECKBOX cb_print     10 150  150       .,            ///
     label("Print details")                             ///
     option("print")
  CHECKBOX cb_ebayes    10 170  300        .,           ///
     label("Generate Empirical Bayes variables")        ///
     option("ebayes")

  CHECKBOX cb_level    220 130   75       .,            ///
     label("CI Level:")                                 ///
     onclickon(main.ed_level.enable)                    ///
     onclickoff(main.ed_level.disable)
  EDIT     ed_level    300   @   40       .,            ///
     label("Level") numonly default(95)                 ///
     option("level")
END

DIALOG graph, tabtitle("Graph Options")
BEGIN
  GROUPBOX gb_graph     10   10  330  _ht2h,            ///
     label("Graph Estimates:")
  RADIO    r_none       15   30   65      .,            ///
     label("None")            first                     ///
     onclickon(program graph_off)                       ///
     onclickoff(program graph_on)                       ///
     option(NONE)
  RADIO    r_fixed      80   30   65      .,            ///
     label("Fixed")           middle                    ///
     option("graph(f)")
  RADIO    r_random    145   30   75      .,            ///
     label("Random")          middle                    ///
     option("graph(r)")
  RADIO    r_ebayes    230   30   95      .,            ///
     label("Emp. Bayes")      last                      ///
     option("graph(e)")

  CHECKBOX cb_cline     15  80  150       .,            ///
     label("Draw Estimate line")                        ///
     option("cline")

  CHECKBOX cb_fmult    200  80   95       .,            ///
     label("Font scale:")                               ///
     onclickon(graph.ed_fmult.enable)                   ///
     onclickoff(graph.ed_fmult.disable)
  EDIT     ed_fmult    300   @   40       .,            ///
     label("Font scale") numonly default(1)             ///
     option("fmult")

  CHECKBOX cb_boxy    200 110   95       .,             ///
     label("Box yscale:")                               ///
     onclickon(graph.ed_boxy.enable)                    ///
     onclickoff(graph.ed_boxy.disable)
  EDIT     ed_boxy    300   @   40       .,             ///
     label("Box yscale") numonly default(1)             ///
     option("boxysca")

  CHECKBOX cb_boxs    200 130   95       .,             ///
     label("Box shade:")                                ///
     onclickon(graph.ed_boxs.enable)                    ///
     onclickoff(graph.ed_boxs.disable)
  EDIT     ed_boxs    300   @   40       .,             ///
     label("Box shading") numonly default(0)            ///
     option("boxshad")

  CHECKBOX cb_ltrunc   15 110   95       .,             ///
     label("Left truncate:")                            ///
     onclickon(graph.ed_ltrunc.enable)                  ///
     onclickoff(graph.ed_ltrunc.disable)
  EDIT     ed_ltrunc  125   @   40       .,             ///
     label("Left truncate") numonly                     ///
     option("ltrunc")

  CHECKBOX cb_rtrunc   15 130  105       .,             ///
     label("Right truncate:")                           ///
     onclickon(graph.ed_rtrunc.enable)                  ///
     onclickoff(graph.ed_rtrunc.disable)
  EDIT     ed_rtrunc  125   @   40       .,             ///
     label("Right truncate") numonly                    ///
     option("rtrunc")

  GROUPBOX gb_gopts7   10 155  330   _ht1h,             ///
     label("Allowed Graph7 Options:")
  EDIT     ed_gopts7   15 175  320       .,             ///
     label("Graph7 Options")
END
 
INCLUDE ifin

SCRIPT main_se_on
BEGIN
  main.tx_se.show
  main.vl_se.show
  main.tx_se.enable
  main.vl_se.enable

  main.tx_var.disable
  main.vl_var.disable
  main.tx_var.hide
  main.vl_var.hide
  
  main.tx_ci.disable
  main.vl_ci.disable
  main.tx_ci.hide
  main.vl_ci.hide
END

SCRIPT main_se_off
BEGIN
  main.tx_se.disable
  main.vl_se.disable
  main.tx_se.hide
  main.vl_se.hide
END

SCRIPT main_var_on
BEGIN
  main.tx_var.show
  main.vl_var.show
  main.tx_var.enable
  main.vl_var.enable

  main.tx_se.disable
  main.vl_se.disable
  main.tx_se.hide
  main.vl_se.hide
  
  main.tx_ci.disable
  main.vl_ci.disable
  main.tx_ci.hide
  main.vl_ci.hide
END

SCRIPT main_var_off
BEGIN
  main.tx_var.disable
  main.vl_var.disable
  main.tx_var.hide
  main.vl_var.hide
END

SCRIPT main_ci_on
BEGIN
  main.tx_ci.show
  main.vl_ci.show
  main.tx_ci.enable
  main.vl_ci.enable

  main.tx_se.disable
  main.vl_se.disable
  main.tx_se.hide
  main.vl_se.hide
  
  main.tx_var.disable
  main.vl_var.disable
  main.tx_var.hide
  main.vl_var.hide
END

SCRIPT main_ci_off
BEGIN
  main.tx_ci.disable
  main.vl_ci.disable
  main.tx_ci.hide
  main.vl_ci.hide
END

PROGRAM graph_on
BEGIN
  call graph.cb_cline.enable
  call graph.cb_fmult.enable
  call graph.cb_boxy.enable
  call graph.cb_boxs.enable
  call graph.cb_ltrunc.enable
  call graph.cb_rtrunc.enable
  call graph.gb_gopts7.enable
  call graph.ed_gopts7.enable
  if graph.cb_fmult {
    call graph.ed_fmult.enable
  }
  if graph.cb_boxy {
    call graph.ed_boxy.enable
  }
  if graph.cb_boxs {
    call graph.ed_boxs.enable
  }
  if graph.cb_ltrunc {
    call graph.ed_ltrunc.enable
  }
  if graph.cb_rtrunc {
    call graph.ed_rtrunc.enable
  }
END

PROGRAM graph_off
BEGIN
  call graph.cb_cline.disable
  call graph.cb_fmult.disable
  call graph.cb_boxy.disable
  call graph.cb_boxs.disable
  call graph.cb_ltrunc.disable
  call graph.cb_rtrunc.disable
  call graph.gb_gopts7.disable
  call graph.ed_gopts7.disable
  if graph.cb_fmult {
    call graph.ed_fmult.disable
  }
  if graph.cb_boxy {
    call graph.ed_boxy.disable
  }
  if graph.cb_boxs {
    call graph.ed_boxs.disable
  }
  if graph.cb_ltrunc {
    call graph.ed_ltrunc.disable
  }
  if graph.cb_rtrunc {
    call graph.ed_rtrunc.disable
  }
END

PROGRAM command
BEGIN
  put "meta "
  if main.r_se {
    varlist main.vl_se 
  }
  if main.r_var {
    varlist main.vl_var 
  }
  if main.r_ci {
    varlist main.vl_ci 
  }
  INCLUDE _ifin_pr
  beginoptions
    option radio(main r_se r_var r_ci)
    optionarg main.vn_id
    option radio(graph r_none r_fixed r_random r_ebayes)
    option main.cb_eform
    option main.cb_print
    option main.cb_ebayes
    option graph.cb_cline
    optionarg graph.ed_fmult
    optionarg graph.ed_boxy
    optionarg graph.ed_boxs
    optionarg graph.ed_ltrunc
    optionarg graph.ed_rtrunc
    put graph.ed_gopts7 
  endoptions
END