anonymous-submission-acl2025's picture
add 21
7694c07
/*-------------------------------------------------------------------------------------------------------------------------------------
Table: Demographic variables. Randomization table. Strata and date FE. ALL PATIENTS THAT SATISFY: Present + Acutely ill + Symptoms>=1
-------------------------------------------------------------------------------------------------------------------------------------*/
preserve
local namestr `" "\it{A. Sample Frame}" "'
di `"`namestr'"'
la var digestiveproblemsintake "Digestive Problems"
la var poorappetiteintake "Poor Appetite"
la var genderpatient "Male (Patient)"
la var breathingintake "Difficulty Breathing"
la var readwrite_fluent_french "Literate (in French)"
la var gender "Male"
la var islamicschool "Islamic School"
la var ltmiddleschool "Primary School"
la var middleschool "Middle School"
la var ethnic_bambara "Bambara"
la var took_meds_before "Meds Before Visit"
la var thinks_malaria "Suspects Malaria"
la var roomshousehold "Rooms in Home"
la var members14oryounger_H "HH Members Under 15"
la var members15orolder_H "HH Members 15 or Older"
la var membersjob_H "HH Members Working"
la var totalincome_H "Total HH Income"
la var mosquitonets_H "Number Mosquito Nets"
la var rent_value_H "Rental Value of Home"
la var symptomsscreening_4 "Poor Appetite"
la var symptomsscreening_7 "Weakness/Fatigue"
la var agepatient "Age"
la var age "Age"
la var total_hh_members_H "Household Size"
la var pred_mal_pos "Predicted Malaria Risk"
la var in_home_survey "In Home Survey"
la var has_valid_rdt_H "Took Home-Based RDT"
la var genderpatient "Male"
la var speak_french "Speaks French"
la var prischoolorless "Primary School or Less"
* LABELS
foreach var in total_hh_members_H HH_frac_14 HH_frac_job income_percap_H rent_value_H HH_frac_nets {
local lbz: variable label `var'
local lbz "`lbz'$^+$"
la var `var' "`lbz'"
}
foreach var in $varlist0 $varlist1 $varlist2 {
local repx ""
if "`var'"!="nobs" & "`var'"!="bobs" local repx "replace `var'=. if dropme==1"
`repx'
}
* Varlists
local v0= wordcount("$varlist0")
local v1= wordcount("$varlist1")
local v2= wordcount("$varlist2")
local totrow= 2*(`v0'+`v1'+`v2')+3
matrix table_randomization=J(`totrow',8,.)
matrix se= J(`totrow',1,.)
local part1 "\multicolumn{7}{l}{\it{A. Sample Frame (Clinic $\times$ Day-Level Observations)}}"
loc f = 2
foreach var in $varlist0 {
local lbz: variable label `var'
local namestr " `namestr' "`lbz'" "\thinspace" "
local q= `f'+1
local part`f' "\enspace `lbz' &"
local part`q' "\thinspace &"
*Regressions
reg `var' patient_voucher doctor_voucher $date, clu($cluvar)
local coeff_patient_voucher: display %19.3f _b[patient_voucher]
local coeff_doctor_voucher: display %19.3f _b[doctor_voucher]
local se_patient_voucher: display %19.3f _se[patient_voucher]
local se_doctor_voucher: display %19.3f _se[doctor_voucher]
matrix table_randomization[`f',2] =`coeff_patient_voucher'
matrix table_randomization[`f',3] =`coeff_doctor_voucher'
matrix table_randomization[`f'+1,2] =`se_patient_voucher'
matrix table_randomization[`f'+1,3] =`se_doctor_voucher'
matrix se[`f'+1,1]=1
*P-value
test patient_voucher==doctor_voucher
local p_value1: display %7.3f `r(p)'
matrix table_randomization[`f',4] =`p_value1'
*P-value
test patient_voucher==doctor_voucher==0
local p_value2: display %7.3f `r(p)'
matrix table_randomization[`f',5] =`p_value2'
*Number of observations
matrix table_randomization[`f',6] =e(N)
*Average for treatment group
sum `var' if doctor_voucher+patient_voucher==0 & e(sample)
local control_mean: display %19.3f r(mean)
local control_sd: display %19.3f r(sd)
matrix table_randomization[`f',1] =`control_mean'
matrix table_randomization[`f'+1,1] =`control_sd'
*Increase the counter of the row
loc f = `f' + 2
}
local sustring ""
local sutest1 ""
local sutest2 ""
local part`f' "\multicolumn{7}{l}{\it{B. Patient Characteristics (Individual-Level Observations)}}"
local f = `f'+1
local namestr " `namestr' "\it{B. Patient Characteristics}" "
foreach var in $varlist1 {
local lbz: variable label `var'
local namestr " `namestr' "`lbz'" "\thinspace" "
local q= `f'+1
local part`f' "\enspace `lbz' &"
local part`q' "\thinspace &"
*Regressions
reg `var' patient_voucher doctor_voucher $date
est store E`var'
local sustring "`sustring' E`var'"
local sutest2 "`sutest2' [E`var'_mean]patient_voucher=[E`var'_mean]doctor_voucher="
local sutest1 "`sutest1' [E`var'_mean]patient_voucher=[E`var'_mean]doctor_voucher="
reg `var' patient_voucher doctor_voucher $date, clu($cluvar)
local coeff_patient_voucher: display %19.3f _b[patient_voucher]
local coeff_doctor_voucher: display %19.3f _b[doctor_voucher]
local se_patient_voucher: display %19.3f _se[patient_voucher]
local se_doctor_voucher: display %19.3f _se[doctor_voucher]
matrix table_randomization[`f',2] =`coeff_patient_voucher'
matrix table_randomization[`f',3] =`coeff_doctor_voucher'
matrix table_randomization[`f'+1,2] =`se_patient_voucher'
matrix table_randomization[`f'+1,3] =`se_doctor_voucher'
matrix se[`f'+1,1]=1
*P-value
test patient_voucher==doctor_voucher
local p_value1: display %7.3f `r(p)'
matrix table_randomization[`f',4] =`p_value1'
*P-value
test patient_voucher==doctor_voucher==0
local p_value2: display %7.3f `r(p)'
matrix table_randomization[`f',5] =`p_value2'
*Number of observations
matrix table_randomization[`f',6] =e(N)
*Average for treatment group
sum `var' if doctor_voucher+patient_voucher==0 & e(sample)
local control_mean: display %19.3f r(mean)
local control_sd: display %19.3f r(sd)
matrix table_randomization[`f',1] =`control_mean'
matrix table_randomization[`f'+1,1] =`control_sd'
*Increase the counter of the row
loc f = `f' + 2
}
mat li table_randomization
****************************
local part`f' "\multicolumn{7}{l}{\it{C. Respondent and Household Characteristics (Individual-Level Observations)}}"
local f = `f'+1
local namestr " `namestr' "\it{C. Respondent Characteristics}" "
foreach var in $varlist2 {
local lbz: variable label `var'
local namestr " `namestr' "`lbz'" "\thinspace" "
local q= `f'+1
local part`f' "\enspace `lbz' &"
local part`q' "\thinspace &"
* REGRESSIONS
reg `var' patient_voucher doctor_voucher $date
est store E`var'
local sustring "`sustring' E`var'"
local sutest2 "`sutest2' [E`var'_mean]patient_voucher=[E`var'_mean]doctor_voucher="
local sutest1 "`sutest1' [E`var'_mean]patient_voucher=[E`var'_mean]doctor_voucher="
reg `var' patient_voucher doctor_voucher $date, clu($cluvar)
local coeff_patient_voucher: display %19.3f _b[patient_voucher]
local coeff_doctor_voucher: display %19.3f _b[doctor_voucher]
local se_patient_voucher: display %19.3f _se[patient_voucher]
local se_doctor_voucher: display %19.3f _se[doctor_voucher]
matrix table_randomization[`f',2] =`coeff_patient_voucher'
matrix table_randomization[`f',3] =`coeff_doctor_voucher'
matrix table_randomization[`f'+1,2] =`se_patient_voucher'
matrix table_randomization[`f'+1,3] =`se_doctor_voucher'
matrix se[`f'+1,1]=1
*P-value
test patient_voucher==doctor_voucher
local p_value1: display %7.3f `r(p)'
matrix table_randomization[`f',4] =`p_value1'
*P-value
test patient_voucher==doctor_voucher==0
local p_value2: display %7.3f `r(p)'
matrix table_randomization[`f',5] =`p_value2'
*Number of observations
matrix table_randomization[`f',6] =e(N)
*Average for treatment group
sum `var' if doctor_voucher+patient_voucher==0 & e(sample)
local control_mean: display %19.3f r(mean)
local control_sd: display %19.3f r(sd)
matrix table_randomization[`f',1] =`control_mean'
matrix table_randomization[`f'+1,1] =`control_sd'
*Increase the counter of the row
loc f = `f' + 2
}
local sutest1 "`sutest1' [Egender_mean]patient_voucher"
local sutest2 "`sutest2' 0"
local df= e(df_r)
mat li table_randomization
matrix rownames table_randomization= `namestr'
local bc = rowsof(table_randomization)
matrix stars = J(`bc',6,0)
local end0= `v0'*2
local start1= `end0'+3
local end1= `start1' + `v1'*2
local start2= `end1'+3
local end2= `totrow'-1
forvalues i=4(1)5{
forvalues k = 2(2)`end0' {
if table_randomization[`k',`i']<=.01{
local star "1"
}
if table_randomization[`k',`i']>.01 & table_randomization[`k',`i']<=.05{
local star "2"
}
if table_randomization[`k',`i']>.05 & table_randomization[`k',`i']<=.10{
local star "3"
}
if table_randomization[`k',`i']>.10{
local star "0"
}
di
matrix stars[`k',`i'] = `star'
}
forvalues k = `start1'(2)`end1' {
if table_randomization[`k',`i']<=.01{
local star "1"
}
if table_randomization[`k',`i']>.01 & table_randomization[`k',`i']<=.05{
local star "2"
}
if table_randomization[`k',`i']>.05 & table_randomization[`k',`i']<=.10{
local star "3"
}
if table_randomization[`k',`i']>.10 {
local star "0"
}
di
matrix stars[`k',`i'] = `star'
}
forvalues k = `start2'(2)`end2' {
if table_randomization[`k',`i']<=.01{
local star "1"
}
if table_randomization[`k',`i']>.01 & table_randomization[`k',`i']<=.05{
local star "2"
}
if table_randomization[`k',`i']>.05 & table_randomization[`k',`i']<=.10{
local star "3"
}
if table_randomization[`k',`i']>.10 {
local star "0"
}
di
matrix stars[`k',`i'] = `star'
}
}
// use critical values from t-distribution, just as is done in regressions
local cv10= abs(invt(`df',.05))
local cv5= abs(invt(`df',.025))
local cv1= abs(invt(`df',.005))
forvalues i=2(1)3{
forvalues k = 2(2)`end0' {
local ttest=abs(table_randomization[`k',`i']/table_randomization[`k'+1,`i'])
if `ttest'<`cv10' {
local star "0"
}
if `ttest'>=`cv10' & `ttest'<`cv5' {
local star "3"
}
if `ttest'>=`cv5' & `ttest'<`cv1' {
local star "2"
}
if `ttest'>=`cv1' & `ttest'!=. {
local star "1"
}
di
matrix stars[`k',`i'] = `star'
}
forvalues k = `start1'(2)`end1' {
local ttest=abs(table_randomization[`k',`i']/table_randomization[`k'+1,`i'])
if `ttest'<`cv10' {
local star "0"
}
if `ttest'>=`cv10' & `ttest'<`cv5' {
local star "3"
}
if `ttest'>=`cv5' & `ttest'<`cv1' {
local star "2"
}
if `ttest'>=`cv1' & `ttest'!=. {
local star "1"
}
di
matrix stars[`k',`i'] = `star'
}
forvalues k = `start2'(2)`end2' {
local ttest=abs(table_randomization[`k',`i']/table_randomization[`k'+1,`i'])
if `ttest'<`cv10' {
local star "0"
}
if `ttest'>=`cv10' & `ttest'<`cv5' {
local star "3"
}
if `ttest'>=`cv5' & `ttest'<`cv1' {
local star "2"
}
if `ttest'>=`cv1' {
local star "1"
}
di
matrix stars[`k',`i'] = `star'
}
}
drop _all
svmat table_randomization
svmat stars
svmat se
g t0=""
forval i=1/`totrow' {
di "`part`i''"
replace t0= "`part`i''" if _n==`i'
}
forval var=1/5 {
tostring table_randomization`var', format("%9.3f") replace force
replace table_randomization`var'="" if table_randomization`var'=="."
replace table_randomization`var'="0"+table_randomization`var' if substr(table_randomization`var',1,1)=="."
replace table_randomization`var'= table_randomization`var'+"\sym{*}" if stars`var'==3
replace table_randomization`var'= table_randomization`var'+"\sym{**}" if stars`var'==2
replace table_randomization`var'= table_randomization`var'+"\sym{***}" if stars`var'==1
}
tostring table_randomization6, format("%9.0f") replace force
replace table_randomization1= "["+table_randomization1+"]" if se1==1
forval i=2/3 {
replace table_randomization`i'="("+table_randomization`i'+")" if se1==1
}
forval i=1/5 {
replace table_randomization`i'= table_randomization`i'+"&" if substr(t0,1,7)!="\multic"
}
replace table_randomization6= "" if table_randomization6=="." & se1==1
replace table_randomization6= table_randomization6+"\\" if table_randomization6!="" | substr(t0,1,7)=="\multic"
replace table_randomization6= table_randomization6+"& \\" if table_randomization6==""
set obs `=_N+2'
g index= _n
replace index=0 if _n==_N-1
sort index
order t0 table_randomization1-table_randomization8
keep t0-table_randomization8
list, clean
#delimit ;
local fn "$footnote0_alt $^+$ indicates that variable was recorded in the home survey only. Variables measured in CFA and duration of illness top-coded at the 99th percentile. CFA610 $\approx$ USD1. $footnote1";
local text0 "\begin{table}[h!] \begin{adjustbox}{max width=.8\textwidth} \begin{threeparttable} \caption{Demographic Characteristics and Randomization Verification} \label{balance} {
\begin{tabular}{l*{7}{c}} \hline\hline & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} & \multicolumn{1}{c}{(3)} & \multicolumn{1}{c}{(4)} & \multicolumn{1}{c}{(5)} & \multicolumn{1}{c}{(6)} \\
& & \multicolumn{2}{c}{Regression Coefficients} & \multicolumn{2}{c}{P-Values} & \\
\cmidrule(lr){3-4} \cmidrule(lr){5-6} &
\multicolumn{1}{c}{\shortstack{Control\\Mean}} & \multicolumn{1}{c}{\shortstack{Patient\\Voucher}} & \multicolumn{1}{c}{\shortstack{Doctor\\ Voucher}} &
\multicolumn{1}{c}{\shortstack{Joint Test\\ PV=DV}} & \multicolumn{1}{c}{\shortstack{Joint Test \\ PV=DV=0}} & \multicolumn{1}{c}{N} \\ \hline";
local textlast "\hline \end{tabular} } \begin{tablenotes}[flushleft] \small
\item `fn'
\end{tablenotes} \end{threeparttable} \end{adjustbox} \end{table}";
#delimit cr
replace t0="`text0'" if _n==1
replace t0="`textlast'" if _n==_N
* replace t0=" & " if t1!="" & _n>=2 & _n<_N & t0==""
outfile t0-table_randomization6 using "$tables/2_balance.tex", noquote replace wide
list
restore