program define tbl2frmt, rclass
*!	Use Gallop's -frmttable- command to convert Stata's -table- output to a Word or TEx table
*!	Version 1.0.2	by Mead Over, CGD		Sept 4, 2014
version 12
syntax varlist [using] [if] [in], row(varname)  ///
	[SUPERRow(varname) stat(string) sd freq SHOWTables tex replace debug  ///
	CTitles(passthru) RTitles(passthru) NOTe(passthru) Title(passthru)  ///
	LAndscape SDec(passthru) PRetext(passthru) POsttext(passthru) ADDTable  ///
	SUBstat(integer 0) SUPERCol(varname) multicol(passthru) hlines(passthru) ///
	hlstyle(passthru) coljust(passthru) noCenter * ]

/*
This program converts a table produced by Stata's -table- command into
a Word or Tex file using Luke Gallop's -frmttable- program.

See the help file, tbl2frmt.sthlp for instructions and examples.

For more examples of how this program is used, see the folder:
N:\Health\AIDS Research\Gates_Efficiency_Effectiveness\
	HIV_AIDS_Modeling_Consortium\South_Africa_TasP_Model_2013\
		Sensitivity_Analysis\Nov_21
and especially the DO files -tasp_analysis_3.do- and -tbl2frmt.do-

*/

marksample touse, novarlist

if "`debug'"=="" {
	local debug quietly
}
else {
	local debug
	local showtables showtables
}

if "`stat'"=="" {
	local stat mean
	local nstats = 1
}
else {
	local nstats: word count `stat'
	if `nstats' > 1 {
		local nvars: word count `varlist'
		if `nstats'~=`nvars' {
			di as err "If the option stat is specified, it must contain either" ///
				_n "a single statistic, to be used on all variables in -varlist-," ///
				_n "or the same number of statistics as there are variables in -varlist-" ///
				_n "Here varlist contains " as txt "`nvars'" as err " variables while the -stat()- option" ///
				_n "contains the " as txt "`nstats'" as err " statistics, " as txt "`stat'"
			exit 198
		}
	}
}
`debug' di _n as txt "Tabulation by the variable specified in the required option, -row()-, " as res "`row'"
`debug' tab `row' if `touse'
	local nrows = r(r)

if "`superrow'"~="" {
	`debug' di _n as txt "Tabulation by the variable specified in the option, -superrow()-, " as res "`superrow'"
	`debug' tab `superrow' if `touse'
		local nsuperrows = r(r)
		local srowlbl : value label `superrow'
		local bysuperrow  by(\`superrow')
}
else {
	local nsuperrows = 0
}

if "`supercol'"~="" {
	`debug' di _n as txt "Tabulation by the variable specified in the option, -supercol()-, " as res "`supercol'"
	`debug' tab `supercol' if `touse'
		local nsupercols = r(r)
		local scollbl : value label `supercol'
	`debug' levelsof `supercol' if `touse', local(sclvls)
}

local nvars = wordcount("`varlist'")
if `substat'>0 & `nvars' ~=2 {
	di as err "When substat(1) is specified, there can be only two variables in -varlist-."
	di as err "Here -varlist- is: " as res "`varlist'"
	exit 198
}
if `substat'>0 & `nvars' ==2 {
	local vname1 : word 1 of `varlist'
	local vname2 : word 2 of `varlist'
}

local contents
tokenize `stat'
local i = 1
foreach var of varlist `varlist' {
	local contents `contents' ``i'' `var'
	local lastvar `var'
	if `nstats'>1 {
		local i = `i' + 1
	}
}
if "`sd'"~="" {
	local sdspec sd `lastvar'
}

tempname stub  // Stub for variables produced by table

preserve	//	Protect the data from -table, name replace-'s destruction

if "`showtables'"=="" {
	local qui quietly
}
`qui' di _n as txt "Output of Stata's -table- command to be formatted by -frmttable-"

`qui' table `row' `supercol' if `touse', `bysuperrow'  ///
	contents(`contents' `sdspec' `freq') name(`stub') replace

tempvar rowstr
tempvar srowstr
tempvar srow_row

decode `row', gen(`rowstr')
sort `superrow' `row' `supercol'
`debug' di _n as txt "Describe and list the small data set created by Stata's -table- command:"
`debug' des _all
`debug' list _all

if "`supercol'"~="" {
	reshape i `superrow' `row'
	reshape j `supercol'
	reshape xij `stub'1  `stub'2
	`debug' reshape wide
	`debug' di _n as txt "After the -reshape- needed to accommodate the -supercol- option,"  ///
			_n " again describe and list the small data set:"
	`debug' des _all
	`debug' list _all
}


*	This version of tbl2frmt requires that nsuperrows>0
*	But in the future, superrows could become optional.
if `nsuperrows' > 0 {
	decode `superrow', gen(`srowstr')
	qui gen str `srow_row' = `srowstr' + ":" + `rowstr'
	local oldN = _N
	local Np1 = _N + 1
	local newN = _N + `nsuperrows'
	qui set obs `newN'

	gen sortorder = _n

*	Logic for inserting a blank row to contain the title for each super_row
	local rownmbr = 1
	local newobsno = `Np1'
	local newsortorder = 0.5
	`debug' levelsof `superrow'
	foreach srowval of numlist `r(levels)' {
		qui replace sortorder = `newsortorder' if _n == `newobsno'
		local lbl : label `srowlbl' `srowval'
		qui replace `srow_row' = "`lbl'"  if _n == `newobsno'
		local newobsno = `newobsno' + 1
		`debug' levelsof `row' if `superrow' == `srowval'
		foreach rowval of numlist  `r(levels)' {
			local rownmbr = `rownmbr' + 1
			local newsortorder = `rownmbr' - 0.5
		}
	}
	sort sortorder
	`debug' list sortorder `srow_row' `stub'* , sepby(`superrow')
}
else {
	di as err "This version of tbl2frmt requires at least one superrow.  Here nsuperrows = " as res "`nsuperrows'"
	//	Following code takes us part way towards allowing execution without the option -supercol()-
	qui gen str `srow_row' = `rowstr'
	local Np1 = _N + 1
	local newN = _N
	gen sortorder = _n
	exit 198
}

*	Construct the matrices of results from which frmttable
*	will assemble a table for all discount rates.
*	This code uses the tiny data set created by -table-.
if `substat'==0  {
	local merge
	foreach i of numlist 1/`nvars' {
		if "`sdec'"~="" {
			tokenize "`sdec'", parse(" ,()")
			local j = 1
			while "`1'"~="" {
				if real("`1'")~=. {  // Token is a number
					if `j'==`i' {
						local sdeccol sdec(`1')
					}
					local j = `j' + 1
				}
				macro shift
			}
		}
		else {
			local sdeccol sdec(1)
		}
		mkmat `stub'`i' , matrix(`stub'`i') rownames(`srow_row')
		`debug' di _n as txt "The small data set created by Stata's -table- command is converted to the following Stata matrix."
		`debug' matrix list `stub'`i'
		`debug' di _n as txt "Call -frmttable- to construct one column of the table"
		`debug' di as res `"frmttable, statmat(`stub'`i') sfmt(fc) `sdeccol' nobrket `merge' nodisplay `options'"'
		frmttable, statmat(`stub'`i') sfmt(fc) `sdeccol' nobrket `merge' nodisplay `options'
		local merge merge
	}
}
else {
	if `substat'>1 {
		di as err "Currently -tbl2frmt- only can handle one substat value."
		di as err "Here the value of substat is: " as res `substat'
		exit 198
	}
	if "`supercol'"=="" {
		local sclvls blank
	}
	local merge
	foreach colval in `sclvls' {
		if "`colval'"=="blank" {
			local suffix
		}
		else {
			local suffix `colval'
		}
		local sdeccol
		/*  //  Get the row titles working before I add the sdec() functionality
		if "`sdec'"~="" {
			tokenize "`sdec'", parse(" ,()")
			local j = 1
			while "`1'"~="" {
			if real("`1'")~=. {  // Token is a number
			if `j'==`i' {
				local sdeccol sdec(`1')
			}
			local j = `j' + 1
			}
			macro shift
			}
		}
		else {
			local sdeccol sdec(1)
		}
		*/
		mkmat `stub'1`suffix' `stub'2`suffix' , matrix(`stub') rownames(`srow_row')
		`debug' di _n as txt "The small data set created by Stata's -table- command is converted to the following Stata matrix."
		`debug' matrix list `stub'
		`debug' di _n as txt "Call -frmttable- to construct one column of the table"
		`debug' di as res `"frmttable, statmat(`stub') sfmt(fc) `sdeccol' nobrket `merge' nodisplay substat(`substat') `options'"'
		frmttable, statmat(`stub') sfmt(fc) `sdeccol' nobrket `merge' nodisplay substat(`substat') `options'
		local merge merge
	}
}

if "`showtables'"~="" {
	di _n as txt "Raw table assembled by -frmttable- from the output of Stata's -table- command"
	frmttable
}

*	Row titles occupy one column, except when substat>0
local ncols_of_rtitles 1

*	Default column titles:
if `"`ctitles'"'== "" {
	local ctitles `"ctitles("' + `ncols_of_rtitles'*`"" ","'
	local i = 1
	foreach var in `varlist' {  //  Can't use -of varlist `varlist'-
		local i = `i' + 1
		local ctitles `ctitles' , `"`var'"'
	}
	local ctitles `ctitles' )
}

*	Default row titles:
local nrtitles = `newN'*(1 + `substat')
local backslash
if `"`rtitles'"'== "" {
	local rtitles rtitles(
	foreach i of numlist 1/`nrtitles' {
		if `substat'==0 {
			`debug' levelsof `srow_row' if _n == `i', clean
			local lvl `r(levels)'
			if "`lvl'"~="" {
				local rtitles `rtitles' `backslash' "`lvl'"
				local backslash \
			}
			else {
				local rtitles `rtitles' `backslash' ""
				local backslash \
			}
		}
		else {  //  if substat>0, rtitles have 2 cols
			local j = int((`i'+1)/2)
			`debug' levelsof sortorder if _n==`j'
			local lvlso `r(levels)'
			local imod = mod(`i',2)
			if substr("`lvlso'",-2,2)==".5"  {
				if `imod'~=0 {
					`debug' levelsof `srow_row' if _n == `j', clean
					local rtitles `rtitles' `backslash' "`r(levels)'" ""
					local backslash \
				}
				else {
					local rtitles `rtitles' `backslash' "" ""
					local backslash \
				}
			}
			else {
				if `imod'~=0 {
					`debug' levelsof `srow_row' if _n == `j', clean
					local lvl `r(levels)'
					local rtitles `rtitles' `backslash' "`lvl'" "`vname1'"
					local backslash \
				}
				else {
					local lvl
					local rtitles `rtitles' `backslash' "" "`vname2'"
					local backslash \
				}
			}
		}
	}
	local rtitles `rtitles' )
}

*	Count the rows of the column titles
`debug' di _n as txt "ctitles is:"
`debug' di as res `"`ctitles'"'
local dummy : subinstr local ctitles "\" "whatever", all count(local nrows_of_cols)
	local nrows_of_cols = `nrows_of_cols' + 1
`debug' di as txt "Number of rows of column titles is: " as res `nrows_of_cols'

*	Count the rows of the row titles
`debug' di _n as txt "rtitles is:"
`debug' di as res `"`rtitles'"'
local dummy : subinstr local rtitles "\" "whatever", all count(local nrows_of_rows)
	local nrows_of_rows = `nrows_of_rows' + 1
`debug' di as txt "Number of rows of row titles is: " as res `nrows_of_rows'

if "`hlines'"=="" {
	if `substat'==0 {
		local rtitlfont rtitlfont(b
		local nrows_ttl = `nrows_of_cols' + `nrows_of_rows'
		local hlines hlines(1  // Start with a narrow line at top
		local hlstyle = "hlstyle(" + (`nrows_of_cols')*"s" + "D"
		foreach i of numlist 1/`nrows_ttl' {
			`debug' levelsof sortorder if _n == `i' - `nrows_of_cols' + 1
			if substr("`r(levels)'",-2,2)==".5" | `i'==`nrows_ttl' {
				local hlines `hlines' 1
				local hlstyle `hlstyle' s
				if `i'>`nrows_of_cols' & `i'~=`nrows_ttl' {
					local rtitlfont `rtitlfont' \ b
				}
			}
			else {
				local hlines `hlines' 0
				local hlstyle `hlstyle' s
				if `i'>`nrows_of_cols' & `i'~=`nrows_ttl' {
					local rtitlfont `rtitlfont' \ plain
				}
			}
		}
		local hlines `hlines' )  // Terminate the option with a -)-
		local hlstyle `hlstyle' )
		local rtitlfont `rtitlfont' )
	}
	else {
		local rtitlfont rtitlfont(b
		local nrows_ttl = `nrows_of_cols' + `nrows_of_rows'
		local hlines = "hlines(1"   // Start with a narrow line at top
		local hlstyle = "hlstyle(s"
		foreach i of numlist 1/`nrows_ttl' {
			if `i'==`nrows_of_cols' {
				local hlstyle `hlstyle' D
			}
			else {
				local hlstyle `hlstyle' s
			}
			local j = int((`i'+1)/2)
			`debug' levelsof sortorder if _n==`j' - `nrows_of_cols' + 1, local(lvlso)
			local imod = mod(`i',2)
			if (substr("`lvlso'",-2,2)==".5" & `imod'==1) | `i'==`nrows_ttl' | `i'==`nrows_of_cols' {
				local hlines `hlines' 1
			}
			else {
				local hlines `hlines' 0
			}
			if (substr("`lvlso'",-2,2)==".5" & `imod'==1)  {
				local rtitlfont `rtitlfont' \ b
			}
			else {
				local rtitlfont `rtitlfont' \ plain
			}
		}
		local hlines `hlines' )  // Terminate the option with a -)-
		local hlstyle `hlstyle' )
		local rtitlfont `rtitlfont' )
	}
}

`debug' di as txt "hlines is: " as res "`hlines'"
`debug' di as txt "hlstyle is: " as res "`hlstyle'"
`debug' di as txt "rtitlfont is: " as res "`rtitlfont'"

*	The small data set created by the -table, name replace- command is no longer necessary.
restore

*	Replay the assembled table in order to create an MS Word version
`debug' di _n as txt "Replay the assembled multi-column table and write it to the Word document"
`debug' di as res   ///
`"frmttable `using', replay  noblankrows statfont(fs11) `rtitlfont' `replace' `ctitles' `rtitles' `note' `title' `hlines' `hlstyle' `landscape' `tex' `pretext' `posttext' `addtable' `multicol' `coljust' `center' "'

frmttable `using', replay  noblankrows statfont(fs11) `rtitlfont' `replace'  ///
	`ctitles' `rtitles' `note' `title' `hlines' `hlstyle' `landscape' `tex'  ///
	`pretext' `posttext' `addtable' `multicol' `coljust' `center'

end   //  End program tbl2frmt
*	Version 1.0.0	May 6, 2014
*	Version 1.0.0	June 18, 2014 Allows the -stat()- option to specify multiple statistics
*	Version 1.0.1	Aug 23, 2014 Allows the coljust() option for table contents and the nocenter option for title & notes
*	Version 1.0.2	Sept 4, 2014 First steps towards making the superrow() option truly optional, but it doesn't work yet.

/*

*******************************
EXAMPLES OF THE USE OF TBL2FRMT
*******************************


tbl2frmt narta16 nartc16 narta33 nartc33 using TasP_tables if central & drate==3,  ///
	replace row(nsub) superrow(nscen) sdec(0) ///
	ctitles(" " "Adults on" "Children on" "Adults on" "Children on" ///
		\ " "  "ART by" "ART by" "ART by" "ART by" ///
		\ "Scenario" " mid-2016" " mid-2016" " mid-2033" " mid-2033")  ///
	rtitles(  ///
		  "Current Guidelines:" \ "  Status quo (SQ)" \ "  Uniform expansion (UE)"  ///
		\ "Universal test and treat (UTT):" \ "  Status quo (SQ)" \ "  Uniform expansion (UE)" ///
		\ "Eligibility < 500 (500):" \ "  Status quo (SQ)" \ "  Uniform expansion (UE)" ///
		\ "Discordant couples (DC):" \ "  Status quo (SQ)" \ "  Prioritised expansion" \ "  Uniform expansion (UE)" ///
		\ "Pregnant women:" \ "  Status quo (SQ)" \ "  Prioritised expansion" \ "  Uniform expansion (UE)" ///
		)  ///
	note("Note: Supply side: Sigma = `sigma', Kmax = `kmax', Scale-up pattern = `extstr'" ///
		"	Demand elasticities: Urban = `e_u', Rural = `e_r' ") ///
	title("Table 4.  Number of patients on ART by scenario")

rescale tc1433 D_tc1433 , billions already(1000000)
rescale newhivt mD_newhiv, millions
table nsub  if central & drate==3, by(nscen) c(mean tc1433 mean newhivt mean D_tc1433 mean mD_newhiv mean CE_newhiv)

tbl2frmt tc1433 newhivt D_tc1433 mD_newhiv CE_newhiv using TasP_tables if central & drate==3,  ///
	replace row(nsub) superrow(nscen) sdec(1,1,1,1,0) ///
	ctitles(  ///
		  " " 	 	" " 			" " 			" "				" " 			"Incremental" ///
		\ " " 	 	"Total cost" 	"Total new" 	"Incremental"	" " 			"cost per" ///
		\ " "  		 "2014-2033" 	"infections"	"cost" 			"Infections" 	"infection" ///
		\ " "  		 "[billion" 	"2014-2033" 	"[billion"		"averted"		"averted" ///
		\ "Scenario" "2013 USD]" 	"[millions]" 	"2013 USD]" 	"[millions]"	"[2013 USD]" )  ///
	rtitles(  ///
		  "Current Guidelines:" \ "  Status quo (SQ)" \ "  Uniform expansion (UE)"  ///
		\ "Universal test and treat (UTT):" \ "  Status quo (SQ)" \ "  Uniform expansion (UE)" ///
		\ "Eligibility < 500 (500):" \ "  Status quo (SQ)" \ "  Uniform expansion (UE)" ///
		\ "Discordant couples (DC):" \ "  Status quo (SQ)" \ "  Prioritised expansion" \ "  Uniform expansion (UE)" ///
		\ "Pregnant women:" \ "  Status quo (SQ)" \ "  Prioritised expansion" \ "  Uniform expansion (UE)" ///
		)  ///
	note("Note: Supply side: Sigma = `sigma', Kmax = `kmax', Scale-up pattern = `extstr'" ///
		"	Demand elasticities: Urban = `e_u', Rural = `e_r' ") ///
	title("Table 5.  Cost, infections averted and cost effectiveness by scenario")  ///
	addtable pretext("\page ")
rescale tc1433 newhivt D_tc1433 mD_newhiv , undo

rescale tc1433 D_tc1433 , billions already(1000000)
rescale dalys mD_dalys, millions
tbl2frmt tc1433 dalys D_tc1433 mD_dalys CE_dalys using TasP_tables if central & drate==3,  ///
	replace row(nsub) superrow(nscen) sdec(1,1,1,1,0) ///
	ctitles(  ///
		  " " 	 	" " 			" " 			" "				" " 			"Incremental" ///
		\ " " 	 	"Total cost" 	"Total" 	"Incremental"		" " 			"cost per" ///
		\ " "  		 "2014-2033" 	"DALYs lost"	"cost" 			"DALYs" 	"DALY" ///
		\ " "  		 "[billion" 	"2014-2033" 	"[billion"		"averted"		"averted" ///
		\ "Scenario" "2013 USD]" 	"[millions]" 	"2013 USD]" 	"[millions]"	"[2013 USD]" )  ///
	rtitles(  ///
		  "Current Guidelines:" \ "  Status quo (SQ)" \ "  Uniform expansion (UE)"  ///
		\ "Universal test and treat (UTT):" \ "  Status quo (SQ)" \ "  Uniform expansion (UE)" ///
		\ "Eligibility < 500 (500):" \ "  Status quo (SQ)" \ "  Uniform expansion (UE)" ///
		\ "Discordant couples (DC):" \ "  Status quo (SQ)" \ "  Prioritised expansion" \ "  Uniform expansion (UE)" ///
		\ "Pregnant women:" \ "  Status quo (SQ)" \ "  Prioritised expansion" \ "  Uniform expansion (UE)" ///
		)  ///
	note("Note: Supply side: Sigma = `sigma', Kmax = `kmax', Scale-up pattern = `extstr'" ///
		"	Demand elasticities: Urban = `e_u', Rural = `e_r' ") ///
	title("Table 6.  Disability-adjusted life years (DALYs) averted and cost utility by scenario")  ///
	addtable pretext("\page ")
rescale tc1433 dalys D_tc1433 mD_dalys , undo

/*	These 2014-16 an 2016 costs are flawed in the data.
rescale tc1416 tc16 , billions already(1000000)
rescale narta16 nartc16 nart16, millions
tbl2frmt tc1416 tc16 narta16 nartc16 nart16 using TasP_tables if central & drate==3,  ///
	replace row(nsub) superrow(nscen) sdec(1,1,1,1,1) ///
	ctitles(  ///
		  " " 	 	" " 			" " 			"Number"	"Number"		"Total " ///
		\ " " 	 	"Total cost" 	"Total cost"	"of adults"	"of children" 	"patients" ///
		\ " "  		 "2014-2016" 	"in 2016" 	"on ART" 	"on ART"		"on ART" ///
		\ " "  		 "[billion" 	"[billion"		"in 2016"	"in 2016"		"in 2016" ///
		\ "Scenario" "2013 USD]" 	"2013 USD]" 	"[millions]" "[millions]"	"[millions]" )  ///
	rtitles(  ///
		  "Current Guidelines:" \ "  Status quo (SQ)" \ "  Uniform expansion (UE)"  ///
		\ "Universal test and treat (UTT):" \ "  Status quo (SQ)" \ "  Uniform expansion (UE)" ///
		\ "Eligibility < 500 (500):" \ "  Status quo (SQ)" \ "  Uniform expansion (UE)" ///
		\ "Discordant couples (DC):" \ "  Status quo (SQ)" \ "  Prioritised expansion" \ "  Uniform expansion (UE)" ///
		\ "Pregnant women:" \ "  Status quo (SQ)" \ "  Prioritised expansion" \ "  Uniform expansion (UE)" ///
		)  ///
	note("Note: Supply side: Sigma = `sigma', Kmax = `kmax', Scale-up pattern = `extstr'" ///
		"	Demand elasticities: Urban = `e_u', Rural = `e_r' ") ///
	title("Table 7.  Cost of ART and patients on ART in 2016 by scenario")  ///
	addtable pretext("\page ")
rescale tc1416 tc16 narta16 nartc16 nart16, undo
*/

table nsubscen drate if central   & combscen>1, by(nscen) c(mean CE_dalys mean CE_newhiv freq) format(%12.0fc) concise

tbl2frmt CE_dalys CE_newhiv if central & drate==3, row(nsub) superrow(nscen)   ///
	ctitles("Scenario" "r = 3%")

tbl2frmt CE_dalys CE_newhiv if central & drate==3, row(nsub) superrow(nscen) substat(1)  ///
	ctitles("Scenario" "Benefit" "r = 3%")

*	Works when rtitles are not specified
tbl2frmt CE_dalys CE_newhiv if central, row(nsub) superrow(nscen) substat(1) supercol(drate) ///
	ctitles(" " "Benefit" "Discount rate" \ "Scenario"  "Measure " "0" "3" "5" "10")  ///
	multicol(1,3,4)  ///
	note("Note: Supply side: Sigma = `sigma', Kmax = `kmax', Scale-up pattern = `extstr'" ///
		"	Demand elasticities: Urban = `e_u', Rural = `e_r' ") ///
	addtable pretext("\page ")  ///
	title("Table __.  Cost of each scenario per DALY or new HIV infection averted"  ///
		"by discount rate from 0% to 10%)" )

*	Also works if rtitles are correctly specified.  Whew:
tbl2frmt CE_dalys CE_newhiv if central using TasP_tables, row(nsub) superrow(nscen) substat(1) supercol(drate) ///
	ctitles(" " "Benefit" "Discount rate" \ "Scenario"  "Measure " "0" "3" "5" "10")  ///
	rtitles(  ///
		  "Current Guidelines:" "" \ "" "" ///
			\ "  Status quo (SQ)"  "DALYs" \ "" "HIV"  ///
			\ "  Uniform expansion (UE)"  "DALYs"\ "" "HIV" ///
		\ "" "" \ "Universal test and treat (UTT):" "" ///
			\ "  Status quo (SQ)" "DALYs" \ " " "HIV"  ///
			\ "  Uniform expansion (UE)"  "DALYs"\ "" "HIV" ///
		\ "" "" \ "Eligibility < 500 (500):"  "" ///
			\ "  Status quo (SQ)" "DALYs" \ " " "HIV"  ///
			\ "  Uniform expansion (UE)"  "DALYs"\ "" "HIV" ///
		\ "" "" \ "Discordant couples (DC):"  ""  ///
			\ "  Status quo (SQ)" "DALYs" \ " " "HIV"  ///
			\ "  Prioritised expansion"  "DALYs"\ "" "HIV" ///
			\ "  Uniform expansion (UE)"  "DALYs"\ "" "HIV" ///
		\ "" "" \ "Pregnant women:"  ""  ///
			\ "  Status quo (SQ)" "DALYs" \ " " "HIV"  ///
			\ "  Prioritised expansion"  "DALYs"\ "" "HIV"  ///
			\ "  Uniform expansion (UE)"  "DALYs"\ "" "HIV" ///
		)  ///
	multicol(1,3,4)  ///
	note("Note: Supply side: Sigma = `sigma', Kmax = `kmax', Scale-up pattern = `extstr'" ///
		"	Demand elasticities: Urban = `e_u', Rural = `e_r' ") ///
	addtable pretext("\page ")  ///
	title("Table __.  Cost of each scenario per DALY or new HIV infection averted"  ///
		"by discount rate from 0% to 10%)" )
*/