capture program drop ceapowersimulatordoc
program define ceapowersimulatordoc
display ""
display " ceapowersimulator.do loads the program ceapowersimulator as well as"
display " a documenation program ceapowersimulatordoc. ceapowersimulator.do"
display " does not perform any calulations. All calculations are performed"
display " by the program ceapowersimulator"
display ""
display " This program simulates trials based on the expected difference"
display " in cost, the expected difference in effect, the SD for cost,"
display " the SD for effect, the correlation of the difference in cost"
display " and effect, and the sample size. It reports the fraction of"
display " experiments in which the 95% CI allow us to be confident that"
display " the therapy is good value (i.e., power), the fraction in which"
display " we can't be confident, and the reasons why we can and cannot"
display " be confident"
display ""
display " Running this program clears the data from the current session"
display " and creates a results dataset named savesssim1.dta. Each time"
display " you run the program it overwrites savessim1.dta"
display ""
display " COMMAND LINE: ceapowersimultor [cost diff] [effect diff] [sd cost]"
display " [sd effect] [correlation] [WTP] [alpha] [sample size]"
display ""
display " Arguments"
display " `""1': Expected difference in cost"
display " `""2': Expected difference in effect"
display " `""3': SD, cost"
display " `""4': SD, Effect"
display " `""5': Correlation"
display " `""6': WTP"
display " `""7': alpha (e.g., 0.05)"
display " `""8': sample size"
display " All arguments are numbers"
display ""
display " Variables in savessim1.dta that are created by the program include the"
display " simulated difference in cost (cdiff), the standard error of cdiff (cse),"
display " the difference in effect (qdiff), the standard error of qdiff (qse),"
display " the correlation of th difference (corr), the point estimate for the"
display " cost-effectiveness ratio (cer), the lower CL for the CER (ll), the upper"
display " CL for the CER (ul), and counts, a variable that records whether or not"
display " the experiment provides confidence about value."
display ""
display " There are 2 general ways in which an experiment provides confidence of"
display " value: either we are confident that the new therapy is good value (cntgv)"
display " or we are confident that that alternative is bad value (catbv). There"
display " are 3 general ways in which an experiment does not provide confidence of"
display " value: either we are not confident that the therapies differ (nctd); we"
display " are confident that the new therapy is bad value (cntbv); or we are"
display " confident that the alternative therapy is good value (catgv). We"
display " identify 13 different types of results that are classified into these 5"
display " categories"
display ""
display " SAVED VALUES"
display ""
display " r(gv): Proportion good value"
display ""
end
capture program drop ceapowersimulator
program define ceapowersimulator,rclass
* ceapowersimulator.do loads the program ceapowersimulator as well as a
* documenation program ceapowersimulatordoc. ceapowersimulator.do does
* not perform any calulations. All calculations are performed by the
* program ceapowersimulator
* This program simulates trials based on the expected difference
* in cost, the expected difference in effect, the SD for cost,
* the SD for effect, the correlation of the difference in cost
* and effect, and the sample size. It reports the fraction of
* experiments in which the 95% CI allow us to be confident that
* the therapy is good value (i.e., power), the fraction in which
* we can't be confident, and the reasons why we can and cannot
* be confident
* Running this program clears the data from the current session
* and creates a results dataset named savesssim1.dta. Each time
* you run the program it overwrites savessim1.dta
* COMMAND LINE: sssimultor [cost diff] [effect diff] [sd cost]
* [sd effect] [correlation] [WTP] [alpha] [sample size]
* Arguments
* `1': Expected difference in cost
* `2': Expected difference in effect
* `3': SD, cost
* `4': SD, Effect
* `5': Correlation
* `6': WTP
* `7': alpha (e.g., 0.05)
* `8': sample size
* All arguments are numbers
* Variables in savessim1.dta that are created by the program include the
* simulated difference in cost (cdiff), the standard error of cdiff (cse),
* the difference in effect (qdiff), the standard error of qdiff (qse),
* the correlation of th difference (corr), the point estimate for the
* cost-effectiveness ratio (cer), the lower CL for the CER (ll), the upper
* CL for the CER (ul), and counts, a variable that records whether or not
* the experiment provides confidence about value.
* There are 2 general ways in which an experiment provides confidence of
* value: either we are confident that the new therapy is good value (cntgv)
* or we are confident that that alternative is bad value (catbv). There
* are 3 general ways in which an experiment does not provide confidence of
* value: either we are not confident that the therapies differ (nctd); we
* are confident that the new therapy is bad value (cntbv); or we are
* confident that the alternative therapy is good value (catgv). We
* identify 13 different types of results that are classified into these 5
* categories
* SAVED VALUES
* r(gv): Proportion good value
* PROGRAM
* DIAGNOSTICS
capture local toolong=`9'
local b1=_rc==0
capture local justright=`8'
local b2=_rc~=0
if ~(`b1'==0&`b2'==0) {
local b3=0
local b4=0
local b5=0
}
if `b1'==0&`b2'==0 {
local b3=~(`5'>=-1&`5'<=1)
local b4=~(0<`7'&`7'<1)
local b5=~(round(`8',1)==`8')
}
if `b1'==0&`b2'==0&`b3'==0&`b4'==0&`b5'==0 {
clear
quietly set obs 1
quietly gen temp=.
quietly save savesssim1,replace
drop _all
local c0=(5*`3')
local c1=`c0'+`1'
local q0=(5*`4')
local q1=`q0'+`2'
local sdc=`3'
local sdq=`4'
local correl=`5'
local wtp=`6'
local alpha=`7'
local n=2*`8'
local jvc=(2*(`n'-1)*(`sdc'^2))/(`n'+`n'-2)
local jvq=2*(`n'-1)*(`sdq'^2)/(`n'+`n'-2)
local jcov=`correl'*(`jvc'^0.5)*(`jvq'^0.5)
matrix cmat1=[`jvc',`jcov']
matrix cmat2=[`jcov',`jvq']
matrix cmat=[cmat1\cmat2]
matrix drop cmat1
matrix drop cmat2
forvalues i=1/1000 {
if round((`i'/100),1)==(`i'/100) {
display `i'
}
drop _all
quietly drawnorm cost qaly,n(`n') m(0 0) cov(cmat)
gen treat=_n>`8'
quietly replace cost=cost+`c0' if treat==0
quietly replace cost=cost+`c1' if treat==1
quietly replace qaly=qaly+`q0' if treat==0
quietly replace qaly=qaly+`q1' if treat==1
quietly corr cost qaly if treat==0,cov
local cv0=r(Var_1)
local qv0=r(Var_2)
local cov0=r(cov_12)
local n0=r(N)
quietly corr cost qaly if treat==1,cov
local cv1=r(Var_1)
local qv1=r(Var_2)
local cov1=r(cov_12)
local n1=r(N)
local jcv= (((`n0'-1)*`cv0')+((`n1'-1)*`cv1'))/(`n0'+`n1'-2)
local jqv= (((`n0'-1)*`qv0')+((`n1'-1)*`qv1'))/(`n0'+`n1'-2)
local jcov=(((`n0'-1)*`cov0')+((`n1'-1)*`cov1'))/(`n0'+`n1'-2)
local corr=`jcov'/((`jcv'^0.5)*(`jqv'^0.5))
quietly ttest cost,by(treat)
local cdiff=r(mu_2)-r(mu_1)
local cse=r(se)
quietly ttest qaly,by(treat)
local qdiff=r(mu_2)-r(mu_1)
local qse=r(se)
quietly keep if _n==1
gen cdiff=`cdiff'
gen cse=`cse'
gen qdiff=`qdiff'
gen qse=`qse'
gen corr=`corr'
quietly keep cdiff cse qdiff qse corr
quietly append using savesssim1
quietly save savesssim1,replace
}
capture drop temp
capture drop if cdiff==.
gen cer=cdiff/qdiff
local tscore=invttail((`n'-2),.025)
gen n=(qdiff*qdiff)-((`tscore'*`tscore')*(qse*qse))
gen o=(cdiff*cdiff)-((`tscore'*`tscore')*(cse*cse))
gen m=(qdiff*cdiff)-((`tscore'*`tscore')*corr*qse*cse)
quietly gen ll=(m-(((m*m)-(n*o))^.5))/n
quietly gen ul=(m+(((m*m)-(n*o))^.5))/n
drop n o m
capture drop counts
quietly gen double counts=.
* Successes
* 10: q>0; p1; w0&llul
* 20: q>0; p2; ulcer
quietly replace counts=20 if qdiff>0&ulcer
* 30: q<0; p1; w0; p1; ~w0&ll0&ll0; p2; ~(ulcer)
quietly replace counts=120 if qdiff>0&ul0&ulcer)
* 130: q<0; p1; ~wul
* 140: q<0; p2; ~(ul100
local n10=r(N)
quietly sum counts if counts==110|counts==120|counts==130|counts==140|counts==150
local n11=r(N)
quietly sum counts if counts==111|counts==121
local n12=r(N)
quietly sum counts if counts==131|counts==141
local n13=r(N)
return scalar gv=`n1'/`den'
display ""
display " Proportion of trials",(100*(1-`alpha')),"% confident of good value: "`n1'/`den'
display " Proportion when new therapy is good value: "`n2'/`den'
display " Proportion when alternate therapy is bad value: "`n3'/`den'
display ""
display " Proportion of trials not",(100*(1-`alpha')),"% confident of good value: "`n10'/`den'
display " Proportion when not confident therapies differ: "`n11'/`den'
display " Proportion when confident therapy is bad value: "`n12'/`den'
display " Proportion when confident alternate therapy is good value: "`n13'/`den'
display ""
}
if ~(`b1'==0&`b2'==0&`b3'==0&`b4'==0&`b5'==0) {
display ""
if `b1'~=0 {
display " Error: Too many arguments"
}
if `b2'~=0 {
display " Error: Too few arguments"
}
if `b3'~=0 {
display " Error: Correlation out of range"
}
if `b4'~=0 {
display " Error: P-value out of range"
}
if `b5'~=0 {
display " Error: Sample size not a counting number"
}
display ""
}
end