/* Dialog (Version 1.0.0) by: T. J. Steichen, steicht@rjrt.com 

metan      VERSION 1.5 30 May 2001   T. J. Steichen: steicht@rjrt.com

Fixed and random effects meta-analysis
--------------------------------------
Syntax: metan varlist [if exp] [in range] [, label(label_vars)   
              fixed fixedi random randomi peto 
              rr or rd cornfield chi2 breslow notable nograph 
              cohen hedges glass nostandard 
              log sortby(sort_vars) ilevel(#) olevel(#) nokeep
              xlabel(#,..,#) force t1(#,..,#) boxsha(#) boxsca(#) texts(#)
              saving(filename) nowt counts nostats nooverall ]

To install in User Statistics menu via Stata commands:
  . window menu append item "stUserStatistics" "Meta-analysis of Binary and Continuous Data (meta&n)" "db metan"
  . window menu refresh
To permanently install, place the commands in your -profile.do- file.

*/

VERSION 8.0

INCLUDE _std_medium
INCLUDE header

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

DIALOG main, label("metan 1.5 - Meta-analysis of Binary and Continuous Data") tabtitle("Main")
BEGIN
  GROUPBOX gb_data      10    5  310  _ht1h,            ///
     label("Type of Data:")
  RADIO    r_binary     15   25  100      .,            ///
     label("Binary Count")      first                   ///
     onclickon(script binary_on)                        ///
     onclickoff(script binary_off)
  RADIO    r_continuous 125  25  100      .,            ///
     label("Continuous")       middle                   ///
     onclickon(script continuous_on)                    ///
     onclickoff(script continuous_off)
  RADIO    r_effect    225   25   85      .,            ///
     label("Effect Size") last                          ///
     onclickon(script effect_on)                        ///
     onclickoff(script effect_off)

/*  end GROUPBOX gb_data  */

  TEXT     tx_binary    10   50  310      .,            ///
     label("Vars for Counts a, b, c, d, in that order")
  VARLIST  vl_binary     @   _ss   @      .,            ///
     label("Vars for a, b, c, d")

  TEXT     tx_contin_exp @   50  310      .,            ///
     label("Vars for Exp. Group: n, mean, sd, in that order")
  VARLIST  vl_contin_exp @   _ss   @      .,            ///
     label("Experimental Group: n, mean, sd")
  TEXT     tx_contin_ctl @   _ss 310      .,            ///
     label("Vars for Control Group: n, mean, sd, in that order")
  VARLIST  vl_contin_ctl @   _ss   @      .,            ///
     label("Control Group: n, mean, sd")

  TEXT     tx_effect     @   50  310      .,            ///
     label("Vars for Effect Sizes: theta, se(theta), in that order")
  VARLIST  vl_effect     @   _ss   @      .,            ///
     label("Effect Sizes: theta, se(theta)")

/*  end vars  */

  GROUPBOX gb_labels     10  130  310  _ht3h,           ///
     label("Labels for Data:")
  CHECKBOX cb_name       20  150  70 .,                 ///
     label("Name:")                                     ///
     onclickon(main.vn_name.enable)                     ///
     onclickoff(main.vn_name.disable)                   ///
     option("id")
  VARNAME vn_name       100  150 210 .,                 ///
     label("Name Variable")
  CHECKBOX cb_year       20  170  70 .,                 ///
     label("Year:")                                     ///
     onclickon(main.vn_year.enable)                     ///
     onclickoff(main.vn_year.disable)                   ///
     option("id")
  VARNAME vn_year       100  170 210  .,                /// 
     label("Year Variable")

/*  end GROUPBOX gb_labels  */

  GROUPBOX gb_sortby     10  200  310 45,               ///
     label("Sort Data:")
  CHECKBOX cb_sortby     20  220   70  .,               ///
     label("  By:")                                     ///
     onclickon(main.vl_sortby.enable)                   ///
     onclickoff(main.vl_sortby.disable)                 ///
     option("id")
  VARLIST vl_sortby     100  220  210  .,               ///
     label("Name Variable")                             ///
     option("sortby")

/*  end GROUPBOX gb_sortby  */
      
  GROUPBOX gb_opts      325    5   80 170,              ///
     label("General")
  TEXT     tx_opts      336   17   60 150,              ///
     label("Options:")

  CHECKBOX cb_nokeep    330   45   70   .,              ///
     label("noKeep")                                    ///
     option("nokeep")

  CHECKBOX cb_ilevel    330   75   60   .,              ///
     label("ilevel:")                                   ///
     onclickon(main.ed_ilevel.enable)                   ///
     onclickoff(main.ed_ilevel.disable)
  EDIT     ed_ilevel    350   _ss  50   .,              ///
     label("ilevel")                                    ///
     numonly default(global S_level)                    ///
     option("ilevel")

  CHECKBOX cb_olevel    330  125   60   .,              ///
     label("olevel:")                                   ///
     onclickon(main.ed_olevel.enable)                   ///
     onclickoff(main.ed_olevel.disable)
  EDIT     ed_olevel    350   _ss  50   .,              ///
     label("olevel")                                    ///
     numonly default(global S_level)                    ///
     option("olevel")

/*  end GROUPBOX gb_opts  */

END

DIALOG metan_b, tabtitle("Binary...")
BEGIN
  GROUPBOX gb_pool 0      10      210      _ht9h,            ///
     label("Pooling Model")
  RADIO    r_fixed 10  30     190     .,                     ///
     label("Fixed, Mantel Haenzel")    first                 ///
     onclickoff(program bd)                                  ///
     option("fixed")
  RADIO    r_fixedi  @         _ss       @         .,        ///
     label("Fixed, Inverse Variance")  middle                ///
     onclickoff(program bd)                                  ///
     option("fixedi")
  RADIO    r_random    @         _ss       @       .,        ///
     label("Random, Mantel Haenzel")   middle                ///
     onclickon(script random_on)                             ///
     onclickoff(program chi2)                                ///
     option("random")
  RADIO    r_randomi  @         _ss       @        .,        ///
     label("Random, Inverse Variance") middle                ///
     onclickon(script random_on)                             ///
     onclickoff(program chi2)                                ///
     option("randomi")
  RADIO    r_peto    @         _ss       @         .,        ///
     label("Peto")                     last                  ///
     onclickon(script peto_on)                               ///
     onclickoff(program cornfield)                           ///
     option("peto")

  GROUPBOX gb_stat 220     10     120 _ht5h,                 ///
     label("Statistic")
  RADIO    r_rr  230       30      80     .,                 ///
     label("RR") first                                       ///
     onclickon(metan_b.cb_log.enable)                        ///
     onclickoff(program rr_off)                              ///
     option("rr")
  RADIO    r_or  @         _ss       @    .,                 ///
     label("OR") middle                                      ///
     onclickon(program or_on)                                ///
     onclickoff(program or_off)                              ///
     option("or")
  RADIO    r_rd  @         _ss       @    .,                 ///
     label("RD") last                                        ///
     option("rd")

  CHECKBOX cb_cornfield 10  140 200  .,                      ///
     label("Use Cornfield CI's")                             ///
     option("cornfield")
  CHECKBOX cb_chi2      10  160 200  .,                      ///
     label("Use Chi-2 Statistic")                            ///
     option("chi2")
  CHECKBOX cb_breslow   10  180 200  .,                      ///
     label("Use Breslow-Day test")                           ///
     option("breslow")

  CHECKBOX cb_log      230  110 200  .,                      ///
     label("Log scaled")                                     ///
     option("log")

  CHECKBOX cb_notable  230  140 200  .,                      ///
     label("noTable")                                        ///
     option("notable")
  CHECKBOX cb_nograph  230  160 200  .,                      ///
     label("noGraph")                                        ///
     option("nograph")
END

DIALOG metan_c, tabtitle("Continuous...")
BEGIN
  GROUPBOX gb_pool    0  10     210      _ht3h,              ///
     label("Pooling Model")
  RADIO    r_fixed   10  30     190        .,                ///
     label("Fixed, Inverse Variance")  first                 ///
     option("fixed")
  RADIO    r_random   @         _ss       @        .,        ///
     label("Random, Inverse Variance") last                  ///
     option("random")

  GROUPBOX gb_stat      220     10     120 _ht7h,            ///
     label("Statistic")
  RADIO    r_cohen      230     30      100    .,            ///
     label("Cohen")      first                               ///
     option("cohen")
  RADIO    r_hedges       @     _ss       @    .,            ///
     label("Hedges")     middle                              ///
     option("hedges")
  RADIO    r_glass        @     _ss       @    .,            ///
     label("Glass")      middle                              ///
     option("glass")
  RADIO    r_nostandard   @     _ss       @    .,            ///
     label("noStandard") last                                ///
     option("nostandard")

  CHECKBOX cb_notable     230  140 200  .,                   ///
     label("noTable")                                        ///
     option("notable")
  CHECKBOX cb_nograph     230  160 200  .,                   ///
     label("noGraph")                                        ///
     option("nograph")
END

DIALOG metan_e, tabtitle("Effect...")
BEGIN
  GROUPBOX gb_pool    0  10     210      _ht3h,              ///
     label("Pooling Model")
  RADIO    r_fixed   10  30     190        .,                ///
     label("Fixed, Inverse Variance")  first                 ///
     option("fixed")
  RADIO    r_random   @  _ss      @        .,                ///
     label("Random, Inverse Variance") last                  ///
     option("random")

  GROUPBOX gb_stat  220     10     120   _ht5h,              ///
     label("Statistic")
  RADIO    r_rr     230     30      80    .,                 ///
     label("RR") first                                       ///
     option("rr")
  RADIO    r_or       @     _ss      @    .,                 ///
     label("OR") middle                                      ///
     option("or")
  RADIO    r_rd       @     _ss      @    .,                 ///
     label("RD") last                                        ///
     option("rd")

  CHECKBOX cb_notable 230  140   200  .,                     ///
     label("noTable")                                        ///
     option("notable")
  CHECKBOX cb_nograph 230  160   200  .,                     ///
     label("noGraph")                                        ///
     option("nograph")
END

DIALOG graph, tabtitle("Graph Opts")
BEGIN

  CHECKBOX cb_saving    10   10  100      .,            ///
     label("Save graph:")                               ///
     onclickon(graph.fi_saving.enable)                  ///
     onclickoff(graph.fi_saving.disable) 
  FILE     fi_saving   110   10  240      .,            ///
     label("File Name")                                 ///
     error("Save filename")                             ///
     dialogtitle("Save graph")                          ///
     filter("Stata Graphs|*.gph")                       ///
     save                                               ///
     option("saving")

/*  end saving  */

  GROUPBOX gb_xlabel    10   40  330  _ht3h,            ///
     label("X-axis Tic Labels (comma between):")

  CHECKBOX cb_xlabel    15   60   45      .,            ///
     label("Set:")                                      ///
     onclickon(script xlabel_on)                        ///
     onclickoff(script xlabel_off) 
  EDIT     ed_xlabel    65    @  270      .,            ///
     label("X Tic labels")                              ///
     option("xlabel")

  CHECKBOX cb_force     15  80  320       .,            ///
     label("Force Scale to Tic Range")                  ///  
     option("force")

/*  end tic labels  */
     
  CHECKBOX cb_counts    15 115   95       .,            ///
     label("Counts")                                    ///
     option("counts")
 
  CHECKBOX cb_nowt      15 135  150       .,            ///
     label("noWeights")                                 ///
     option("nowt")

  CHECKBOX cb_nostats   15 155   95       .,            ///
     label("noStats")                                   ///
     option("nostats")

  CHECKBOX cb_nooverall 15 175   95       .,            ///
     label("noOverall")                                 ///
     option("nooverall")

/*  end switches  */

  CHECKBOX cb_texts    200 115   95       .,            ///
     label("Font scale:")                               ///
     onclickon(graph.ed_texts.enable)                   ///
     onclickoff(graph.ed_texts.disable)
  EDIT     ed_texts    300   @   40       .,            ///
     label("Font scale") numonly default(1)             ///
     option("texts")

  CHECKBOX cb_boxy     200 145   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("boxsca")

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

/*  end sets  */

  GROUPBOX gb_gopts7   10 200  330   _ht1h,             ///
     label("Allowed Graph7 Options:")
  EDIT     ed_gopts7   15 220  320       .,             ///
     label("Graph7 Options")

/*  end Graph7 opts  */

END

INCLUDE ifin

SCRIPT binary_on
BEGIN
  main.tx_binary.show
  main.vl_binary.show
  main.tx_binary.enable
  main.vl_binary.enable

  main.tx_effect.disable
  main.vl_effect.disable
  main.tx_effect.hide
  main.vl_effect.hide
  
  main.tx_contin_exp.disable
  main.vl_contin_exp.disable
  main.tx_contin_exp.hide
  main.vl_contin_exp.hide
  
  main.tx_contin_ctl.disable
  main.vl_contin_ctl.disable
  main.tx_contin_ctl.hide
  main.vl_contin_ctl.hide

  graph.cb_counts.enable
END

SCRIPT binary_off
BEGIN
  main.tx_binary.disable
  main.vl_binary.disable
  main.tx_binary.hide
  main.vl_binary.hide
  
  graph.cb_counts.disable
END

SCRIPT continuous_on
BEGIN
  main.tx_contin_exp.show
  main.vl_contin_exp.show
  main.tx_contin_exp.enable
  main.vl_contin_exp.enable

  main.tx_contin_ctl.show
  main.vl_contin_ctl.show
  main.tx_contin_ctl.enable
  main.vl_contin_ctl.enable

  main.tx_binary.disable
  main.vl_binary.disable
  main.tx_binary.hide
  main.vl_binary.hide
  
  main.tx_effect.disable
  main.vl_effect.disable
  main.tx_effect.hide
  main.vl_effect.hide
END

SCRIPT continuous_off
BEGIN
  main.tx_contin_exp.disable
  main.vl_contin_exp.disable
  main.tx_contin_exp.hide
  main.vl_contin_exp.hide
  
  main.tx_contin_ctl.disable
  main.vl_contin_ctl.disable
  main.tx_contin_ctl.hide
  main.vl_contin_ctl.hide
END

SCRIPT effect_on
BEGIN
  main.tx_effect.show
  main.vl_effect.show
  main.tx_effect.enable
  main.vl_effect.enable

  main.tx_binary.disable
  main.vl_binary.disable
  main.tx_binary.hide
  main.vl_binary.hide
  
  main.tx_contin_exp.disable
  main.vl_contin_exp.disable
  main.tx_contin_exp.hide
  main.vl_contin_exp.hide
  
  main.tx_contin_ctl.disable
  main.vl_contin_ctl.disable
  main.tx_contin_ctl.hide
  main.vl_contin_ctl.hide
END

SCRIPT effect_off
BEGIN
  main.tx_effect.disable
  main.vl_effect.disable
  main.tx_effect.hide
  main.vl_effect.hide
END

SCRIPT random_on
BEGIN
  metan_b.cb_breslow.disable
  metan_b.cb_chi2.disable
END

SCRIPT peto_on
BEGIN
  metan_b.cb_breslow.disable
  metan_b.cb_cornfield.disable
END

PROGRAM bd
BEGIN
  if metan_b.r_or {
     call metan_b.cb_breslow.enable
  }
END

PROGRAM chi2
BEGIN
  if metan_b.r_or & !(metan_b.r_random | metan_b.r_randomi) {
     call metan_b.cb_chi2.enable
  }
END

PROGRAM cornfield
BEGIN
  if metan_b.r_or {
     call metan_b.cb_cornfield.enable
  }
END

PROGRAM or_on
BEGIN
  call metan_b.cb_log.enable
  call metan_b.r_peto.enable
  if !metan_b.r_peto {
     call metan_b.cb_cornfield.enable
  }
  if !(metan_b.r_random | metan_b.r_randomi) {
     call metan_b.cb_chi2.enable
  }
  call metan_b.cb_breslow.enable
END

PROGRAM or_off
BEGIN
  if !metan_b.r_rr {
     call metan_b.cb_log.disable
  }
  call metan_b.r_peto.disable
  call metan_b.cb_cornfield.disable
  call metan_b.cb_chi2.disable
  call metan_b.cb_breslow.disable
END

PROGRAM rr_off
BEGIN
  if !metan_b.r_or {
     call metan_b.cb_log.disable
  }
END

SCRIPT xlabel_on
BEGIN
   graph.ed_xlabel.enable
   graph.cb_force.enable
END   

SCRIPT xlabel_off
BEGIN
   graph.ed_xlabel.disable 
   graph.cb_force.disable
END

PROGRAM command
BEGIN
  put " metan "
  if main.r_binary {
    varlist main.vl_binary 
  }
  if main.r_continuous {
    varlist main.vl_contin_exp main.vl_contin_ctl 
  }
  if main.r_effect {
    varlist main.vl_effect 
  }
  INCLUDE _ifin_pr
  beginoptions
    if main.cb_name | main.cb_year {
      put "label("
      if main.cb_name {
        put "namevar=" main.vn_name
      }
      if main.cb_name & main.cb_year {
        put ", "
      }
      if main.cb_year {
        put "yearvar=" main.vn_year
      }
      put ") "
    }
    optionarg main.vl_sortby
    optionarg main.ed_ilevel
    optionarg main.ed_olevel
    option main.cb_nokeep
    if main.r_binary {
      option radio(metan_b r_fixed r_fixedi r_random r_randomi r_peto)
      option radio(metan_b r_rr r_or r_rd)
      option metan_b.cb_cornfield
      option metan_b.cb_chi2
      option metan_b.cb_breslow
      option metan_b.cb_log
      option metan_b.cb_nograph
      option metan_b.cb_notable
    }
    if main.r_continuous {
      option radio(metan_c r_fixed r_random)
      option radio(metan_c r_cohen r_hedges r_glass r_nostandard)
      option metan_c.cb_nograph
      option metan_c.cb_notable
    }
    if main.r_effect {
      option radio(metan_e r_fixed r_random)
      option radio(metan_e r_rr r_or r_rd)
      option metan_e.cb_nograph
      option metan_e.cb_notable
    }
    optionarg graph.fi_saving
    optionarg graph.ed_xlabel
    option graph.cb_force
    option graph.cb_counts
    option graph.cb_nowt
    option graph.cb_nostats
    option graph.cb_nooverall
    optionarg graph.ed_texts
    optionarg graph.ed_boxy
    optionarg graph.ed_boxs
    put graph.ed_gopts7
  endoptions
END