anonymous-submission-acl2025's picture
add 21
7694c07
* *******************************************************
* PROGRAM: DocPat_TablePrograms
* PROGRAMNER: Simone Schaner
* PURPOSE: Programs to make tables for LSS analysis
* DATE CREATED: 5/1/2019
* *******************************************************
**************************************************************************************************************
* e-class program to product bootstrapped SEs using replicant datasets and pre-specified controls
* note: we assume the "dofirst" bit has already been executed for the main spec, and just
* needs to be done on loops over the replication set
**************************************************************************************************************
cap prog drop boot_ols
prog define boot_ols, eclass
syntax anything [if] [in] , REPName(string) REPPath(string) NUMreps(integer) [DOFirst(string)] [MAindata(string)]
marksample touse
preserve
set more off
* FIRST RUN THE MAIN REGRESSION
qui `anything' `if'
tempfile starthere
save `starthere'
mat beta= e(b) /* get initial parameter vector */
local cols= colsof(beta)
local obs=e(N)
local dvar=e(depvar)
local rname: rowfullnames e(V)
local cname: colfullnames e(V)
mat reps=J(`numreps',`cols',.)
* NEXT DO A WHOLE BUNCH OF REPLICATIONS
local i=1
while `i'<=`numreps' {
qui {
drop _all
use "`reppath'/`repname'`i'"
`dofirst'
`anything' `if' [`wt']
mat reps[`i',1]=e(b)
}
di `i'
local ++i
} /* closes loop where we do command over and over */
* NEXT CALCULATE STANDARD ERRORS
drop _all
svmat reps
mat accum var= * [iw=1/`numreps'], dev nocons
mat colnames var= `cname'
mat rownames var= `rname'
* DISPLAY RESULTS
*di _n in gr "Bootstrapped Results"
drop _all
use `starthere'
qui `anything' `if'
* ereturn post beta var, esample(`touse') obs(`obs') depname(`dvar')
ereturn repost b=beta V=var
ereturn display
restore
end
**************************************************************************************************************
* main table w/o one-sided tests
**************************************************************************************************************
cap prog drop docpat_theory_lso
prog define docpat_theory_lso
est clear
syntax varlist [if], TEXWID(string) [Table(string)] [LCONT(varlist)] [TYPE(string)] [FOOTnote(string)] [PREHEAD1(string)] ///
[PREHEAD2(string)] [TITLE(string)] [LABel(string)] WIDC(string) [EXTRAC1(string)] [EXTRAC2(string)] ///
[EXTRAHEAD(string)] [EXTRAVARHead(string)] CLUVar(string) TESTOF(string) SIGNIFEVIDENCE(string) [PARTIAL(string)]
qui {
local q= 2
local colcount= wordcount("`varlist'")+1
local seclast= `q'-1
// locals to assist in making the table
local ester=1
forval i=1/`q' {
local eststr`i' ""
}
// label covariates
la var patient_voucher "$\beta_P$: Patient Voucher"
la var doctor_voucher "$\beta_D$: Doctor Voucher"
local counter=1
local varhead ""
local paren`counter' ""
local outcount=1
foreach out in `varlist' {
// GET LABELS HERE
local labelq : variable label `out'
local varhead "`varhead'& `labelq'" //this is the label for columns
pdslasso `out' patient_voucher doctor_voucher (`lcont') `if', clu(`cluvar') partial(`partial')
test patient_voucher=doctor_voucher
local n1= r(p)
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDV `combo'
local sign = sign(_b[patient_voucher]-_b[doctor_voucher])
local n1= 1-normal(`sign'*sqrt(r(chi2)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="ge" local p_one "`combo'"
local n1= normal(`sign'*sqrt(r(chi2)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="le" local p_one "`combo'"
estadd local p_oneside `p_one'
test patient_voucher=doctor_voucher=0
local n1= r(p)
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDV0 `combo'
qui sum `out' if e(sample) & doctor_voucher+patient_voucher==0
local DV: display %7.3f `r(mean)'
estadd local DV `DV'
tokenize `testof'
estadd local test_of "``outcount''"
tokenize `signifevidence'
estadd local signif_evidence "``outcount''"
est store E`ester'
local eststr`counter' "`eststr`counter'' E`ester'"
local paren`counter' "`paren`counter'' & (`ester')" // column numbers
local ++ester
local ++outcount
}
local ++counter
} //end qui loop
* FIRST PANEL
esttab `eststr1' using "`table'", keep(patient_voucher doctor_voucher) label noabbrev `type' replace nogaps nomtit nonum ///
stats(space p_PVDV test_of signif_evidence space DV N, fmt(0 0 0 0 0 a3 a0) labels("\emph{P-values and theory-driven tests}" "\enspace $\beta_P=\beta_D$" "\enspace Test for mechanism:" "\enspace Significant evidence of mechanism:" " " "Mean (Control)" "N")) ///
nonote star(* 0.10 ** 0.05 *** 0.01) `extrac1' ///
b(a2) se(a2) noline subs("\beta\_" "\beta_") ///
prehead("\begin{table}[ht!] \begin{adjustbox}{max width=`texwid'\textwidth} \begin{threeparttable} \caption{`title'} \label{`label'} {\begin{tabular}{l*{`colcount'}{C{`widc'}}} \toprule \toprule `paren1' `extrahead' \\ `varhead' `extravarhead' \\ \toprule ") ///
postfoot(\hline \end{tabular} } \begin{tablenotes}[flushleft] \small \item `footnote' \end{tablenotes} \end{threeparttable} \end{adjustbox} \end{table})
end
**************************************************************************************************************
* theory driven tests in table w/ het tmt by above/below median malaria risk
* this table uses bootstrapped standard errors coupled w/ variable selection via pdslasso
**************************************************************************************************************
cap prog drop docpat_hettable_theory_lso
prog define docpat_hettable_theory_lso
est clear
syntax varlist [if], TEXWID(string) [Table(string)] [TYPE(string)] [FOOTnote(string)] [PREHEAD1(string)] PATH(string) SETNAME(string) ///
[PREHEAD2(string)] [TITLE(string)] [LABel(string)] WIDC(string) [EXTRAC1(string)] [EXTRAC2(string)] [PARTIAL(string)] ///
[EXTRAHEAD(string)] [EXTRAVARHead(string)] CLUVar(string) TESTOFH(string) SIGNIFEVIDENCEH(string) TESTOFL(string) SIGNIFEVIDENCEL(string) ///
NUMreps(integer) DODO(string) LCONT(string)
qui {
preserve
local q= 2
local colcount= wordcount("`varlist'")+1
local seclast= `q'-1
// locals to assist in making the table
local ester=1
forval i=1/`q' {
local eststr`i' ""
}
// label covariates
la var patient_voucher_high "$\delta_{PH}$: Patient Voucher $\times$ High Risk"
la var doctor_voucher_high "$\delta_{DH}$: Doctor Voucher $\times$ High Risk"
la var patient_voucher_low "$\delta_{PL}$: Patient Voucher $\times$ Low Risk"
la var doctor_voucher_low "$\delta_{DL}$: Doctor Voucher $\times$ Low Risk"
la var above_med_pos "$\theta$: High Malaria Risk"
local counter=1
local varhead ""
local paren`counter' ""
local outcount=1
tempfile theuser
save `theuser'
foreach out in `varlist' {
drop _all
use `theuser'
// GET LABELS HERE
local labelq : variable label `out'
local varhead "`varhead'& `labelq'" //this is the label for columns
// step 1 :: select covariates using PDS lasso
pdslasso `out' patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos (`lcont') `if', clu(`cluvar') partial(`partial')
local totcont= "`e(xselected)' `e(xpartial)'"
// step 2 :: bootstrap this thing
boot_ols reg `out' patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos `totcont' `if', reppath(`path') repname(`setname') num(`numreps') dofirst(`dodo')
* NB: since this is bootstrapping after double post lasso, recalculate p-values to be based on asymptotic inference
* this ensures that we use asymptotics for both one and two-sided tests
test patient_voucher_high = doctor_voucher_high
local n1= 2*(1-normal(sqrt(r(F))))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDVhigh `combo'
local sign = sign(_b[patient_voucher_high]-_b[doctor_voucher_high])
local n1= 1-normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="ge" local p_one_high "`combo'"
local n1= normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="le" local p_one_high "`combo'"
test patient_voucher_low = doctor_voucher_low
local n1= 2*(1-normal(sqrt(r(F))))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDVlow `combo'
local sign = sign(_b[patient_voucher_low]-_b[doctor_voucher_low])
local n1= 1-normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="ge" local p_one_low "`combo'"
local n1= normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="le" local p_one_low "`combo'"
qui sum `out' if e(sample) & doctor_voucher + patient_voucher ==0 & above_med_pos==0
local DV: display %7.3f `r(mean)'
estadd local DV `DV'
tokenize `testofh'
estadd local test_of_h "``outcount''"
tokenize `signifevidenceh'
estadd local signif_evidence_h "``outcount''"
tokenize `testofl'
estadd local test_of_l "``outcount''"
tokenize `signifevidencel'
estadd local signif_evidence_l "``outcount''"
est store E`ester'
local eststr`counter' "`eststr`counter'' E`ester'"
local paren`counter' "`paren`counter'' & (`ester')" // column numbers
local ++ester
local ++outcount
}
local ++counter
} //end qui loop
* FIRST PANEL
esttab `eststr1' using "`table'", keep(patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos) label noabbrev `type' replace nogaps nomtit nonum ///
stats(space p_PVDVhigh test_of_h signif_evidence_h space p_PVDVlow test_of_l signif_evidence_l space DV N, fmt(0 0 0 0 0 0 0 0 0 a2 a0) labels("\emph{P-values and theory-driven tests}" "\enspace $\delta_{PH}=\delta_{DH}$" "\enspace Test for mechanism:" "\enspace Significant evidence of mechanism:" " " "\enspace $\delta_{PL}=\delta_{DL}$" "\enspace Test for mechanism:" "\enspace Significant evidence of mechanism:" " " "Mean (Control, Low Risk)" "N")) ///
nonote star(* 0.10 ** 0.05 *** 0.01) `extrac1' ///
b(a2) se(a2) noline subs("\beta\_" "\beta_") ///
prehead("\begin{table}[ht!] \begin{adjustbox}{max width=`texwid'\textwidth} \begin{threeparttable} \caption{`title'} \label{`label'} {\begin{tabular}{l*{`colcount'}{C{`widc'}}} \toprule \toprule `paren1' `extrahead' \\ `varhead' `extravarhead' \\ \toprule ") ///
postfoot(\hline \end{tabular} } \begin{tablenotes}[flushleft] \small \item `footnote' \end{tablenotes} \end{threeparttable} \end{adjustbox} \end{table})
restore
end
**************************************************************************************************************
* theory driven tests in table w/ het tmt by above/below median malaria risk
* this table uses bootstrapped standard errors coupled w/ variable selection via pdslasso
**************************************************************************************************************
cap prog drop docpat_het_theory_lso_simple
prog define docpat_het_theory_lso_simple
est clear
syntax varlist [if], TEXWID(string) [Table(string)] [TYPE(string)] [FOOTnote(string)] [PREHEAD1(string)] PATH(string) SETNAME(string) ///
[PREHEAD2(string)] [TITLE(string)] [LABel(string)] WIDC(string) [EXTRAC1(string)] [EXTRAC2(string)] [PARTIAL(string)] ///
[EXTRAHEAD(string)] [EXTRAVARHead(string)] CLUVar(string) ///
NUMreps(integer) DODO(string) LCONT(string)
qui {
preserve
local q= 2
local colcount= wordcount("`varlist'")+1
local seclast= `q'-1
// locals to assist in making the table
local ester=1
forval i=1/`q' {
local eststr`i' ""
}
// label covariates
la var patient_voucher_high "$\delta_{PH}$: Patient Voucher $\times$ High Risk"
la var doctor_voucher_high "$\delta_{DH}$: Doctor Voucher $\times$ High Risk"
la var patient_voucher_low "$\delta_{PL}$: Patient Voucher $\times$ Low Risk"
la var doctor_voucher_low "$\delta_{DL}$: Doctor Voucher $\times$ Low Risk"
la var above_med_pos "$\theta$: High Malaria Risk"
local counter=1
local varhead ""
local paren`counter' ""
local outcount=1
tempfile theuser
save `theuser'
foreach out in `varlist' {
drop _all
use `theuser'
// GET LABELS HERE
local labelq : variable label `out'
local varhead "`varhead'& `labelq'" //this is the label for columns
// step 1 :: select covariates using PDS lasso
pdslasso `out' patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos (`lcont') `if', clu(`cluvar') partial(`partial')
local totcont= "`e(xselected)' `e(xpartial)'"
// step 2 :: bootstrap this thing
boot_ols reg `out' patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos `totcont' `if', reppath(`path') repname(`setname') num(`numreps') dofirst(`dodo')
* NB: since this is bootstrapping after double post lasso, recalculate p-values to be based on asymptotic inference
* this ensures that we use asymptotics for both one and two-sided tests
test patient_voucher_high = doctor_voucher_high
local n1= 2*(1-normal(sqrt(r(F))))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDVhigh `combo'
local sign = sign(_b[patient_voucher_high]-_b[doctor_voucher_high])
local n1= 1-normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="ge" local p_one_high "`combo'"
local n1= normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="le" local p_one_high "`combo'"
test patient_voucher_low = doctor_voucher_low
local n1= 2*(1-normal(sqrt(r(F))))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDVlow `combo'
local sign = sign(_b[patient_voucher_low]-_b[doctor_voucher_low])
local n1= 1-normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="ge" local p_one_low "`combo'"
local n1= normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="le" local p_one_low "`combo'"
qui sum `out' if e(sample) & doctor_voucher + patient_voucher ==0 & above_med_pos==0
local DV: display %7.3f `r(mean)'
estadd local DV `DV'
tokenize `testofh'
estadd local test_of_h "``outcount''"
tokenize `signifevidenceh'
estadd local signif_evidence_h "``outcount''"
tokenize `testofl'
estadd local test_of_l "``outcount''"
tokenize `signifevidencel'
estadd local signif_evidence_l "``outcount''"
est store E`ester'
local eststr`counter' "`eststr`counter'' E`ester'"
local paren`counter' "`paren`counter'' & (`ester')" // column numbers
local ++ester
local ++outcount
}
local ++counter
} //end qui loop
* FIRST PANEL
esttab `eststr1' using "`table'", keep(patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos) label noabbrev `type' replace nogaps nomtit nonum ///
stats(space p_PVDVhigh p_PVDVlow space DV N, fmt(0 0 0 0 a2 a0) labels("\emph{P-values}" "\enspace $\delta_{PH}=\delta_{DH}$" "\enspace $\delta_{PL}=\delta_{DL}$" " " "Mean (Control, Low Risk)" "N")) ///
nonote star(* 0.10 ** 0.05 *** 0.01) `extrac1' ///
b(a2) se(a2) noline subs("\beta\_" "\beta_") ///
prehead("\begin{table}[ht!] \begin{adjustbox}{max width=`texwid'\textwidth} \begin{threeparttable} \caption{`title'} \label{`label'} {\begin{tabular}{l*{`colcount'}{C{`widc'}}} \toprule \toprule `paren1' `extrahead' \\ `varhead' `extravarhead' \\ \toprule ") ///
postfoot(\hline \end{tabular} } \begin{tablenotes}[flushleft] \small \item `footnote' \end{tablenotes} \end{threeparttable} \end{adjustbox} \end{table})
restore
end
**************************************************************************************************************
* table w/ panels that uses lasso throughout and bootstrapping for the het effects
* NOTE: no theory-driven tests for this one
**************************************************************************************************************
cap prog drop docpat_pantable_lso
prog define docpat_pantable_lso
est clear
syntax varlist [if], TEXWID(string) [Table(string)] [TYPE(string)] [FOOTnote(string)] [PREHEAD1(string)] ///
[PREHEAD2(string)] [TITLE(string)] [LABel(string)] WIDC(string) [EXTRAC1(string)] [EXTRAC2(string)] ///
[EXTRAHEAD(string)] [EXTRAVARHead(string)] CLUVar(string) [PARTIAL(string)] NUMreps(integer) DODO(string) ///
SETname(string) PATH(string) LCONT(string)
qui {
local q= 2
local colcount= wordcount("`varlist'")+1
local seclast= `q'-1
// locals to assist in making the table
local ester=1
forval i=1/`q' {
local eststr`i' ""
}
// label covariates
la var patient_voucher "\enspace $\beta_P$: Patient Voucher"
la var doctor_voucher "\enspace $\beta_D$: Doctor Voucher"
la var patient_voucher_high "\enspace $\delta_{PH}$: Patient Voucher $\times$ High Risk"
la var doctor_voucher_high "\enspace $\delta_{DH}$: Doctor Voucher $\times$ High Risk"
la var patient_voucher_low "\enspace $\delta_{PL}$: Patient Voucher $\times$ Low Risk"
la var doctor_voucher_low "\enspace $\delta_{DL}$: Doctor Voucher $\times$ Low Risk"
la var above_med_pos "\enspace $\theta$: High Malaria Risk"
local counter=1
local varhead ""
local paren`counter' ""
tempfile startfile
save `startfile'
foreach out in `varlist' {
// GET LABELS HERE
local headz`counter' "\emph{Panel A. No Interactions}" // this is the label for panels
local labelq : variable label `out'
local varhead "`varhead'& `labelq'" //this is the label for columns
pdslasso `out' patient_voucher doctor_voucher (`lcont') `if', clu(`cluvar') partial(`partial')
test patient_voucher=doctor_voucher
local n1= r(p)
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDV `combo'
test patient_voucher=doctor_voucher=0
local n1= r(p)
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDV0 `combo'
qui sum `out' if e(sample) & infotreat==0 & treat_scheduled==1
estadd scalar DV=r(mean)
est store E`ester'
local eststr`counter' "`eststr`counter'' E`ester'"
local paren`counter' "`paren`counter'' & (`ester')" // column numbers
local ++ester
}
local ++counter
// NOW DO INTERACTIONS
local varhead ""
local paren`counter' ""
foreach out in `varlist' {
drop _all
use `startfile'
// get labels here
local headz`counter' "\emph{Panel B. Interactions with Predicted Malaria Probability}" // this is the label for panels
local labelq : variable label `out'
local varhead "`varhead'& `labelq'" //this is the label for columns
// step 1 :: select covariates using PDS lasso
pdslasso `out' patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos (`lcont') `if', clu(`cluvar') partial(`partial')
local totcont= "`e(xselected)' `e(xpartial)'"
// step 2 :: bootstrap this thing
boot_ols reg `out' patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos `totcont' `if', reppath(`path') repname(`setname') num(`numreps') dofirst(`dodo')
test patient_voucher_high = doctor_voucher_high
local n1= 2*(1-normal(sqrt(r(F))))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDVhigh `combo'
test patient_voucher_low = doctor_voucher_low
local n1= 2*(1-normal(sqrt(r(F))))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDVlow `combo'
qui sum `out' if e(sample) & doctor_voucher + patient_voucher ==0
local DV: display %7.3f `r(mean)'
estadd local DV `DV'
estadd local space=""
est store E`ester'
local eststr`counter' "`eststr`counter'' E`ester'"
local paren`counter' "`paren`counter'' & (`ester')" // column numbers
local ++ester
}
local ++counter
} //end qui loop
* FIRST PANEL
esttab `eststr1' using "`table'", keep(patient_voucher doctor_voucher) label noabbrev `type' replace nogaps nomtit nonum ///
stats(space p_PVDV p_PVDV0 , fmt( 0 0 0) labels("\emph{P-Values: Two-Sided Tests} \textcolor{white}{XXXXXXXXXXXXXXXXXX}" "\enspace $\beta_P=\beta_D$" "\enspace $\beta_P=\beta_D=0$")) ///
nonote star(* 0.10 ** 0.05 *** 0.01) `extrac1' ///
b(a2) se(a2) noline subs("\beta\_" "\beta_") ///
prehead("\begin{table}[ht!] \begin{adjustbox}{max width=`texwid'\textwidth} \begin{threeparttable} \caption{`title'} \label{`label'} {\begin{tabular}{l*{`colcount'}{C{`widc'}}} \toprule \toprule `paren1' `extrahead' \\ `varhead' `extravarhead' \\ \toprule \multicolumn{`colcount'}{l}{`headz1'} \\")
* SECOND PANEL
esttab `eststr2' using "`table'", append keep(patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos) ///
label noabbrev `type' nogaps nomtit nonum ///
stats(space p_PVDVhigh p_PVDVlow space DV N, fmt(0 0 0 0 a2 a0) ///
labels("\emph{P-values: Two-Sided Tests} \textcolor{white}{XXXXXXXXXXXXXXXXXX}" "\enspace $\delta_{PH}=\delta_{DH}$" "\enspace $\delta_{PL}=\delta_{DL}$" " " "Mean (Control)" "N")) ///
nonote eqlabels(none) star(* 0.10 ** 0.05 *** 0.01) `extrac2' ///
b(a2) se(a2) noline subs("\beta\_" "\beta_") ///
prehead("{ \begin{tabular}{l*{8}{C{`widc'}}} \\ \multicolumn{`colcount'}{l}{`headz`q''} \\") ///
postfoot(\hline \end{tabular} } \begin{tablenotes}[flushleft] \small \item `footnote' \end{tablenotes} \end{threeparttable} \end{adjustbox} \end{table})
end
**************************************************************************************************************
* table to show one-panel / main effects using lasso, no theory driven tests
**************************************************************************************************************
cap prog drop docpat_p1_lso
prog define docpat_p1_lso
est clear
syntax varlist [if], TEXWID(string) [Table(string)] [TYPE(string)] [FOOTnote(string)] [PREHEAD1(string)] ///
[PREHEAD2(string)] [TITLE(string)] [LABel(string)] WIDC(string) [EXTRAC1(string)] [EXTRAC2(string)] ///
[EXTRAHEAD(string)] [EXTRAVARHead(string)] CLUVar(string) [PARTIAL(string)] LCONT(string)
qui {
local q= 2
local colcount= wordcount("`varlist'")+1
local seclast= `q'-1
// locals to assist in making the table
local ester=1
forval i=1/`q' {
local eststr`i' ""
}
// label covariates
la var patient_voucher "$\beta_P$: Patient Voucher"
la var doctor_voucher "$\beta_D$: Doctor Voucher"
local counter=1
local varhead ""
local paren`counter' ""
foreach out in `varlist' {
// GET LABELS HERE
local labelq : variable label `out'
local varhead "`varhead'& `labelq'" //this is the label for columns
pdslasso `out' patient_voucher doctor_voucher (`lcont') `if', clu(`cluvar') partial(`partial')
test patient_voucher=doctor_voucher
local n1= r(p)
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDV `combo'
test patient_voucher=doctor_voucher=0
local n1= r(p)
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDV0 `combo'
qui sum `out' if e(sample) & doctor_voucher+patient_voucher==0
local DV: display %7.3f `r(mean)'
estadd local DV `DV'
est store E`ester'
local eststr`counter' "`eststr`counter'' E`ester'"
local paren`counter' "`paren`counter'' & (`ester')" // column numbers
local ++ester
}
local ++counter
} //end qui loop
* FIRST PANEL
esttab `eststr1' using "`table'", keep(patient_voucher doctor_voucher) label noabbrev `type' replace nogaps nomtit nonum ///
stats(space p_PVDV p_PVDV0 space DV N, fmt(0 0 0 0 a2 a0) labels("\emph{P-values}" "\enspace $\beta_P=\beta_D$" "\enspace $\beta_P=\beta_D=0$" " " "Mean (Control)" "N")) ///
nonote star(* 0.10 ** 0.05 *** 0.01) `extrac1' ///
b(a2) se(a2) noline subs("\beta\_" "\beta_") ///
prehead("\begin{table}[ht!] \begin{adjustbox}{max width=`texwid'\textwidth} \begin{threeparttable} \caption{`title'} \label{`label'} {\begin{tabular}{l*{`colcount'}{C{`widc'}}} \toprule \toprule `paren1' `extrahead' \\ `varhead' `extravarhead' \\ \toprule ") ///
postfoot(\hline \end{tabular} } \begin{tablenotes}[flushleft] \small \item `footnote' \end{tablenotes} \end{threeparttable} \end{adjustbox} \end{table})
end
**************************************************************************************************************
* table that looks at impact of patient information
**************************************************************************************************************
cap prog drop docpat_pat_aux_lso
prog define docpat_pat_aux_lso
est clear
syntax varlist [if], TEXWID(string) [Table(string)] [TYPE(string)] [FOOTnote(string)] [PREHEAD1(string)] ///
[PREHEAD2(string)] [TITLE(string)] [LABel(string)] WIDC(string) [EXTRAC1(string)] [EXTRAC2(string)] ///
[EXTRAHEAD(string)] [EXTRAVARHead(string)] CLUVar(string) [PARTIAL(string)] LCONT(string)
qui {
local q= 2
local colcount= wordcount("`varlist'")+1
local seclast= `q'-1
// locals to assist in making the table
local ester=1
forval i=1/`q' {
local eststr`i' ""
}
// label covariates
la var patient_voucher "\enspace Patient Voucher"
la var doctor_voucher "\enspace Doctor Voucher"
la var patient_info "\enspace Patient Information"
la var pat_infoXno_voucher "\enspace Patient Information $\times$ No Voucher"
la var pat_infoXdoc_voucher "\enspace Doctor Voucher $\times$ Patient Information"
la var pat_infoXpat_voucher "\enspace Patient Voucher $\times$ Patient Information"
local counter=1
local varhead ""
local paren`counter' ""
foreach out in `varlist' {
// GET LABELS HERE
local headz`counter' "\emph{Panel A. Overall Effects}" // this is the label for panels
local labelq : variable label `out'
local varhead "`varhead'& `labelq'" //this is the label for columns
pdslasso `out' patient_info (`lcont') `if', clu(`cluvar') partial(`partial')
qui sum `out' if e(sample) & patient_info==0
local control_PI: display %10.3f `r(mean)'
estadd local control_PI `control_PI'
est store E`ester'
local eststr`counter' "`eststr`counter'' E`ester'"
local paren`counter' "`paren`counter'' & (`ester')" // column numbers
local ++ester
}
local ++counter
local varhead ""
local paren`counter' ""
foreach out in `varlist' {
// GET LABELS HERE
local headz`counter' "\emph{Panel B. By Voucher Treatment Group}" // this is the label for panels
local labelq : variable label `out'
local varhead "`varhead'& `labelq'" //this is the label for columns
pdslasso `out' patient_info patient_voucher doctor_voucher pat_infoXpat_voucher pat_infoXdoc_voucher ($date $patient) `if', clu(`cluvar') partial(`partial')
test patient_voucher = doctor_voucher
local n1= r(p)
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_NoVPVDV `combo'
qui sum `out' if e(sample) & patient_info +doctor_voucher + patient_voucher ==0
estadd scalar noPInoVoucher=r(mean)
estadd local space=""
est store E`ester'
local eststr`counter' "`eststr`counter'' E`ester'"
local paren`counter' "`paren`counter'' & (`ester')" // column numbers
local ++ester
}
local ++counter
} //end qui loop
* FIRST PANEL
esttab `eststr1' using "`table'", keep(patient_info) label noabbrev `type' replace nogaps nomtit nonum ///
stats(space control_PI, fmt( 0 0) labels(" " "\enspace Mean (No PI)\textcolor{white}{XXXXXXXXXXXXXXX}")) ///
nonote star(* 0.10 ** 0.05 *** 0.01) `extrac1' ///
b(a2) se(a2) noline subs("\beta\_" "\beta_") ///
prehead("\begin{table}[ht!] \begin{adjustbox}{max width=`texwid'\textwidth} \begin{threeparttable} \caption{`title'} \label{`label'} {\begin{tabular}{l*{`colcount'}{C{`widc'}}} \toprule \toprule `paren1' `extrahead' \\ `varhead' `extravarhead' \\ \toprule \multicolumn{`colcount'}{l}{`headz1'} \\")
* SECOND PANEL
esttab `eststr2' using "`table'", append keep(patient_info patient_voucher doctor_voucher pat_infoXpat_voucher pat_infoXdoc_voucher) ///
label noabbrev `type' nogaps nomtit nonum ///
stats(space p_NoVPVDV space noPInoVoucher N, fmt(0 0 0 a3 a0) ///
labels("\enspace \emph{P-Values}" "\enspace \enspace Patient Voucher=Doctor Voucher" " " "\enspace Mean (No PI, No Voucher)" "\enspace N")) ///
nonote eqlabels(none) star(* 0.10 ** 0.05 *** 0.01) `extrac2' ///
b(a2) se(a2) noline subs("\beta\_" "\beta_") ///
prehead("{ \begin{tabular}{l*{8}{C{`widc'}}} \\ \multicolumn{`colcount'}{l}{`headz`q''} \\") ///
postfoot(\hline \end{tabular} } \begin{tablenotes}[flushleft] \small \item `footnote' \end{tablenotes} \end{threeparttable} \end{adjustbox} \end{table})
end
**************************************************************************************************************
* table that looks at impact of patient information
**************************************************************************************************************
cap prog drop docpat_pat_lso
prog define docpat_pat_lso
est clear
syntax varlist [if], TEXWID(string) [Table(string)] [TYPE(string)] [FOOTnote(string)] [PREHEAD1(string)] ///
[PREHEAD2(string)] [TITLE(string)] [LABel(string)] WIDC(string) [EXTRAC1(string)] [EXTRAC2(string)] ///
[EXTRAHEAD(string)] [EXTRAVARHead(string)] CLUVar(string) [PARTIAL(string)] LCONT(string)
qui {
local q= 2
local colcount= wordcount("`varlist'")+1
local seclast= `q'-1
// locals to assist in making the table
local ester=1
forval i=1/`q' {
local eststr`i' ""
}
// label covariates
la var patient_voucher "\enspace Patient Voucher"
la var doctor_voucher "\enspace Doctor Voucher"
la var patient_info "\enspace Patient Information"
la var doctor_voucher_x_patient_info "\enspace Doctor Voucher $\times$ Patient Information"
la var patient_voucher_x_patient_info "\enspace Patient Voucher $\times$ Patient Information"
local counter=1
local varhead ""
local paren`counter' ""
foreach out in `varlist' {
// GET LABELS HERE
local headz`counter' "\emph{Panel B. By Voucher Treatment Group}" // this is the label for panels
local labelq : variable label `out'
local varhead "`varhead'& `labelq'" //this is the label for columns
pdslasso `out' patient_info patient_voucher doctor_voucher patient_voucher_x_patient_info doctor_voucher_x_patient_info ($date $patient) `if', clu(`cluvar') partial(`partial')
test patient_voucher = doctor_voucher
local n1= r(p)
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_NoVPVDV `combo'
qui sum `out' if e(sample) & patient_info +doctor_voucher + patient_voucher ==0
estadd scalar noPInoVoucher=r(mean)
estadd local space=""
est store E`ester'
local eststr`counter' "`eststr`counter'' E`ester'"
local paren`counter' "`paren`counter'' & (`ester')" // column numbers
local ++ester
}
local ++counter
} //end qui loop
* FIRST PANEL
esttab `eststr1' using "`table'", replace keep(patient_info patient_voucher doctor_voucher patient_voucher_x_patient_info doctor_voucher_x_patient_info ) ///
label noabbrev `type' nogaps nomtit nonum ///
stats(space noPInoVoucher N, fmt(0 a3 a0) ///
labels(" " "\enspace Mean (No PI, No Voucher)" "\enspace N")) ///
nonote eqlabels(none) star(* 0.10 ** 0.05 *** 0.01) `extrac1' ///
b(a2) se(a2) noline subs("\beta\_" "\beta_") ///
prehead("\begin{table}[h!] \begin{adjustbox}{max width=`texwid'\textwidth} \begin{threeparttable} \caption{`title'} \label{`label'} {\begin{tabular}{l*{`colcount'}{C{`widc'}}} \toprule \toprule `paren1' `extrahead' \\ `varhead' `extravarhead' \\ \toprule ") ///
postfoot(\hline \end{tabular} } \begin{tablenotes}[flushleft] \small \item `footnote' \end{tablenotes} \end{threeparttable} \end{adjustbox} \end{table})
end
**************************************************************************************************************
* table that looks at impact of doctor information
**************************************************************************************************************
cap prog drop docpat_doc_lso
prog define docpat_doc_lso
est clear
syntax varlist [if], TEXWID(string) [Table(string)] [TYPE(string)] [FOOTnote(string)] [PREHEAD1(string)] ///
[PREHEAD2(string)] [TITLE(string)] [LABel(string)] WIDC(string) [EXTRAC1(string)] [EXTRAC2(string)] ///
[EXTRAHEAD(string)] [EXTRAVARHead(string)] CLUVar(string) [PARTIAL(string)] LCONT(string)
qui {
local q= 2
local colcount= wordcount("`varlist'")+1
local seclast= `q'-1
// locals to assist in making the table
local ester=1
forval i=1/`q' {
local eststr`i' ""
}
// label covariates
la var patient_voucher "\enspace Patient Voucher"
la var doctor_voucher "\enspace Doctor Voucher"
la var infotreat "\enspace Doctor Information"
la var doctor_voucher_x_doctor_info "\enspace Doctor Voucher $\times$ Doctor Information"
la var patient_voucher_x_doctor_info "\enspace Patient Voucher $\times$ Doctor Information"
local counter=1
local varhead ""
local paren`counter' ""
foreach out in `varlist' {
// GET LABELS HERE
local labelq : variable label `out'
local varhead "`varhead'& `labelq'" //this is the label for columns
pdslasso `out' infotreat patient_voucher doctor_voucher patient_voucher_x_doctor_info doctor_voucher_x_doctor_info ($date $patient) `if', clu(`cluvar') partial(`partial')
test patient_voucher = doctor_voucher
local n1= r(p)
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_NoVPVDV `combo'
qui sum `out' if e(sample) & infotreat +doctor_voucher + patient_voucher ==0
local noDInoVoucher: display %7.3f `r(mean)'
estadd local noDInoVoucher `noDInoVoucher'
est store E`ester'
local eststr`counter' "`eststr`counter'' E`ester'"
local paren`counter' "`paren`counter'' & (`ester')" // column numbers
local ++ester
}
local ++counter
} //end qui loop
* FIRST PANEL
esttab `eststr1' using "`table'", replace keep(infotreat patient_voucher doctor_voucher patient_voucher_x_doctor_info doctor_voucher_x_doctor_info) ///
label noabbrev `type' nogaps nomtit nonum ///
stats(space noDInoVoucher N, fmt(0 a3 a0) ///
labels(" " "\enspace Mean (No DI, No Voucher)" "\enspace N")) ///
nonote eqlabels(none) star(* 0.10 ** 0.05 *** 0.01) `extrac1' ///
b(a2) se(a2) noline subs("\beta\_" "\beta_") ///
prehead("\begin{table}[h!] \begin{adjustbox}{max width=`texwid'\textwidth} \begin{threeparttable} \caption{`title'} \label{`label'} {\begin{tabular}{l*{`colcount'}{C{`widc'}}} \toprule \toprule `paren1' `extrahead' \\ `varhead' `extravarhead' \\ \toprule ") ///
postfoot(\hline \end{tabular} } \begin{tablenotes}[flushleft] \small \item `footnote' \end{tablenotes} \end{threeparttable} \end{adjustbox} \end{table})
end
**************************************************************************************************************
* ROBUSTNESS: main table w/ theory-driven tests (no lasso)
**************************************************************************************************************
cap prog drop docpat_p1_theory
prog define docpat_p1_theory
est clear
syntax varlist [if], TEXWID(string) [Table(string)] [EXtra(varlist)] [TYPE(string)] [FOOTnote(string)] [PREHEAD1(string)] ///
[PREHEAD2(string)] [TITLE(string)] [LABel(string)] WIDC(string) [EXTRAC1(string)] [EXTRAC2(string)] ///
[EXTRAHEAD(string)] [EXTRAVARHead(string)] CLUVar(string) TESTOF(string) SIGNIFEVIDENCE(string)
qui {
local q= 2
local colcount= wordcount("`varlist'")+1
local seclast= `q'-1
// locals to assist in making the table
local ester=1
forval i=1/`q' {
local eststr`i' ""
}
// label covariates
la var patient_voucher "$\beta_P$: Patient Voucher"
la var doctor_voucher "$\beta_D$: Doctor Voucher"
local counter=1
local varhead ""
local paren`counter' ""
local outcount=1
foreach out in `varlist' {
// GET LABELS HERE
local labelq : variable label `out'
local varhead "`varhead'& `labelq'" //this is the label for columns
reg `out' patient_voucher doctor_voucher `extra' `if', clu(`cluvar')
test patient_voucher=doctor_voucher
local n1= r(p)
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDV `combo'
local sign = sign(_b[patient_voucher]-_b[doctor_voucher])
local n1= ttail(r(df_r),`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="ge" local p_one "`combo'"
local n1= 1-ttail(r(df_r),`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="le" local p_one "`combo'"
estadd local p_oneside `p_one'
test patient_voucher=doctor_voucher=0
local n1= r(p)
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDV0 `combo'
qui sum `out' if e(sample) & doctor_voucher+patient_voucher==0
local DV: display %7.3f `r(mean)'
estadd local DV `DV'
tokenize `testof'
estadd local test_of "``outcount''"
tokenize `signifevidence'
estadd local signif_evidence "``outcount''"
est store E`ester'
local eststr`counter' "`eststr`counter'' E`ester'"
local paren`counter' "`paren`counter'' & (`ester')" // column numbers
local ++ester
local ++outcount
}
local ++counter
} //end qui loop
* FIRST PANEL
esttab `eststr1' using "`table'", keep(patient_voucher doctor_voucher) label noabbrev `type' replace nogaps nomtit nonum ///
stats(space p_PVDV test_of signif_evidence space DV N, fmt(0 0 0 0 0 a3 a0) labels("\emph{P-values and theory-driven tests}" "\enspace $\beta_P=\beta_D$" "\enspace Test for mechanism:" "\enspace Significant evidence of mechanism:" " " "Mean (Control)" "N")) ///
nonote star(* 0.10 ** 0.05 *** 0.01) `extrac1' ///
b(a2) se(a2) noline subs("\beta\_" "\beta_") ///
prehead("\begin{table}[ht!] \begin{adjustbox}{max width=`texwid'\textwidth} \begin{threeparttable} \caption{`title'} \label{`label'} {\begin{tabular}{l*{`colcount'}{C{`widc'}}} \toprule \toprule `paren1' `extrahead' \\ `varhead' `extravarhead' \\ \toprule ") ///
postfoot(\hline \end{tabular} } \begin{tablenotes}[flushleft] \small \item `footnote' \end{tablenotes} \end{threeparttable} \end{adjustbox} \end{table})
end
**************************************************************************************************************
* ROBUSTNESS: het effects table w/ theory-driven tests (no lasso)
**************************************************************************************************************
cap prog drop docpat_hettable_theory
prog define docpat_hettable_theory
est clear
syntax varlist [if], TEXWID(string) [Table(string)] [EXtra(varlist)] [TYPE(string)] [FOOTnote(string)] [PREHEAD1(string)] ///
[PREHEAD2(string)] [TITLE(string)] [LABel(string)] WIDC(string) [EXTRAC(string)] [PARTIAL(string)] ///
[EXTRAHEAD(string)] [EXTRAVARHead(string)] CLUVar(string) TESTOFH(string) SIGNIFEVIDENCEH(string) TESTOFL(string) SIGNIFEVIDENCEL(string) ///
DODO(string) PATH(string) SETNAME(string) NUMReps(string)
qui {
preserve
local q= 2
local colcount= wordcount("`varlist'")+1
local seclast= `q'-1
// locals to assist in making the table
local ester=1
forval i=1/`q' {
local eststr`i' ""
}
// label covariates
la var patient_voucher_high "$\delta_{PH}$: Patient Voucher $\times$ High Risk"
la var doctor_voucher_high "$\delta_{DH}$: Doctor Voucher $\times$ High Risk"
la var patient_voucher_low "$\delta_{PL}$: Patient Voucher $\times$ Low Risk"
la var doctor_voucher_low "$\delta_{DL}$: Doctor Voucher $\times$ Low Risk"
la var above_med_pos "$\theta$: High Malaria Risk"
local counter=1
local varhead ""
local paren`counter' ""
local outcount=1
tempfile theuser
save `theuser'
foreach out in `varlist' {
drop _all
use `theuser'
// GET LABELS HERE
local labelq : variable label `out'
local varhead "`varhead'& `labelq'" //this is the label for columns
// bootstrap this thing
boot_ols reg `out' patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos `extrac' `if', reppath(`path') repname(`setname') num(`numreps') dofirst(`dodo')
* NB: recalculate p-values to be based on asymptotic inference
* code written so we use asymptotics for both one and two-sided tests
test patient_voucher_high = doctor_voucher_high
local n1= 2*(1-normal(sqrt(r(F))))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDVhigh `combo'
local sign = sign(_b[patient_voucher_high]-_b[doctor_voucher_high])
local n1= 1-normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="ge" local p_one_high "`combo'"
local n1= normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="le" local p_one_high "`combo'"
test patient_voucher_low = doctor_voucher_low
local n1= 2*(1-normal(sqrt(r(F))))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDVlow `combo'
local sign = sign(_b[patient_voucher_low]-_b[doctor_voucher_low])
local n1= 1-normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="ge" local p_one_low "`combo'"
local n1= normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="le" local p_one_low "`combo'"
* CHECK THIS
qui sum `out' if doctor_voucher + patient_voucher ==0 & above_med_pos==0
local DV: display %7.3f `r(mean)'
estadd local DV `DV'
tokenize `testofh'
estadd local test_of_h "``outcount''"
tokenize `signifevidenceh'
estadd local signif_evidence_h "``outcount''"
tokenize `testofl'
estadd local test_of_l "``outcount''"
tokenize `signifevidencel'
estadd local signif_evidence_l "``outcount''"
est store E`ester'
local eststr`counter' "`eststr`counter'' E`ester'"
local paren`counter' "`paren`counter'' & (`ester')" // column numbers
local ++ester
local ++outcount
}
local ++counter
} //end qui loop
* FIRST PANEL
esttab `eststr1' using "`table'", keep(patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos) label noabbrev `type' replace nogaps nomtit nonum ///
stats(space p_PVDVhigh test_of_h signif_evidence_h space p_PVDVlow test_of_l signif_evidence_l space DV N, fmt(0 0 0 0 0 0 0 0 0 a2 a0) labels("\emph{P-values and theory-driven tests}" "\enspace $\delta_{PH}=\delta_{DH}$" "\enspace Test for mechanism:" "\enspace Significant evidence of mechanism:" " " "\enspace $\delta_{PL}=\delta_{DL}$" "\enspace Test for mechanism:" "\enspace Significant evidence of mechanism:" " " "Mean (Control, Low Risk)" "N")) ///
nonote star(* 0.10 ** 0.05 *** 0.01) `extrac1' ///
b(a2) se(a2) noline subs("\beta\_" "\beta_") ///
prehead("\begin{table}[ht!] \begin{adjustbox}{max width=`texwid'\textwidth} \begin{threeparttable} \caption{`title'} \label{`label'} {\begin{tabular}{l*{`colcount'}{C{`widc'}}} \toprule \toprule `paren1' `extrahead' \\ `varhead' `extravarhead' \\ \toprule ") ///
postfoot(\hline \end{tabular} } \begin{tablenotes}[flushleft] \small \item `footnote' \end{tablenotes} \end{threeparttable} \end{adjustbox} \end{table})
restore
end
**************************************************************************************************************
* TABLE FOR ANTIBIOTICS
**************************************************************************************************************
cap prog drop docpat_hettable_lso
prog define docpat_hettable_lso
est clear
syntax varlist [if], TEXWID(string) [Table(string)] [TYPE(string)] [FOOTnote(string)] [PREHEAD1(string)] PATH(string) SETNAME(string) ///
[PREHEAD2(string)] [TITLE(string)] [LABel(string)] WIDC(string) [EXTRAC1(string)] [EXTRAC2(string)] [PARTIAL(string)] ///
[EXTRAHEAD(string)] [EXTRAVARHead(string)] CLUVar(string) ///
NUMreps(integer) DODO(string) LCONT(string)
qui {
preserve
local q= 2
local colcount= wordcount("`varlist'")+1
local seclast= `q'-1
// locals to assist in making the table
local ester=1
forval i=1/`q' {
local eststr`i' ""
}
// label covariates
la var patient_voucher_high "$\delta_{PH}$: Patient Voucher $\times$ High Risk"
la var doctor_voucher_high "$\delta_{DH}$: Doctor Voucher $\times$ High Risk"
la var patient_voucher_low "$\delta_{PL}$: Patient Voucher $\times$ Low Risk"
la var doctor_voucher_low "$\delta_{DL}$: Doctor Voucher $\times$ Low Risk"
la var above_med_pos "$\theta$: High Malaria Risk"
local counter=1
local varhead ""
local paren`counter' ""
local outcount=1
tempfile theuser
save `theuser'
foreach out in `varlist' {
drop _all
use `theuser'
// GET LABELS HERE
local labelq : variable label `out'
local varhead "`varhead'& `labelq'" //this is the label for columns
// step 1 :: select covariates using PDS lasso
pdslasso `out' patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos (`lcont') `if', clu(`cluvar') partial(`partial')
local totcont= "`e(xselected)' `e(xpartial)'"
// step 2 :: bootstrap this thing
boot_ols reg `out' patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos `totcont' `if', reppath(`path') repname(`setname') num(`numreps') dofirst(`dodo')
* NB: since this is bootstrapping after double post lasso, recalculate p-values to be based on asymptotic inference
* this ensures that we use asymptotics for both one and two-sided tests
test patient_voucher_high = doctor_voucher_high
local n1= 2*(1-normal(sqrt(r(F))))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDVhigh `combo'
local sign = sign(_b[patient_voucher_high]-_b[doctor_voucher_high])
local n1= 1-normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="ge" local p_one_high "`combo'"
local n1= normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="le" local p_one_high "`combo'"
test patient_voucher_low = doctor_voucher_low
local n1= 2*(1-normal(sqrt(r(F))))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
estadd local p_PVDVlow `combo'
local sign = sign(_b[patient_voucher_low]-_b[doctor_voucher_low])
local n1= 1-normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="ge" local p_one_low "`combo'"
local n1= normal(`sign'*sqrt(r(F)))
local star ""
if `n1'<=.01 local star "\sym{***}"
if `n1'>.01 & `n1'<=.05 local star "\sym{**}"
if `n1'>.05 & `n1'<=.1 local star "\sym{*}"
local n2 = trim("`: display %10.3f `n1''")
local combo "`n2'`star'"
tokenize `oneside'
if "``outcount''"=="le" local p_one_low "`combo'"
qui sum `out' if e(sample) & doctor_voucher + patient_voucher ==0 & above_med_pos==0
local DV: display %7.3f `r(mean)'
estadd local DV `DV'
tokenize `testofhigh'
estadd local test_of_high "``outcount''"
tokenize `testoflow'
estadd local test_of_low "``outcount''"
estadd local p_one_high `p_one_high'
estadd local p_one_low `p_one_low'
est store E`ester'
local eststr`counter' "`eststr`counter'' E`ester'"
local paren`counter' "`paren`counter'' & (`ester')" // column numbers
local ++ester
local ++outcount
}
local ++counter
} //end qui loop
* FIRST PANEL
esttab `eststr1' using "`table'", keep(patient_voucher_high doctor_voucher_high patient_voucher_low doctor_voucher_low above_med_pos) label noabbrev `type' replace nogaps nomtit nonum ///
stats(space p_PVDVhigh p_PVDVlow space DV N, fmt(0 0 0 0 a2 a0) labels("\emph{P-values}" "\enspace $\delta_{PH}=\delta_{DH}$" "\enspace $\delta_{PL}=\delta_{DL}$" " " "Mean (Control, Low Risk)" "N")) ///
nonote star(* 0.10 ** 0.05 *** 0.01) `extrac1' ///
b(a2) se(a2) noline subs("\beta\_" "\beta_") ///
prehead("\begin{table}[ht!] \begin{adjustbox}{max width=`texwid'\textwidth} \begin{threeparttable} \caption{`title'} \label{`label'} {\begin{tabular}{l*{`colcount'}{C{`widc'}}} \toprule \toprule `paren1' `extrahead' \\ `varhead' `extravarhead' \\ \toprule ") ///
postfoot(\hline \end{tabular} } \begin{tablenotes}[flushleft] \small \item `footnote' \end{tablenotes} \end{threeparttable} \end{adjustbox} \end{table})
restore
end