I’m trying to create a summary table from a set of RD regressions using the collect command. I have several outcome variables and multiple running variables, and I want to stack the results for each outcome into a single column for better presentation. I have successfully run my regressions and collected results for each outcome and running variable and am able to show the different models into one column per outcome. But I also want to show the mean of the outcome variable and the number of observations used in each regression. Here is my code using an example dataset:
The output comes out like this: 
But I would like to add "Mean" (of the dependent var.) and "Number of observations" (used in the regression) under each regression output.
I can get the values I want using the estpost command but I would like to combine this with the table above:
Thanks in advance!
Code:
clear all
use "https://raw.githubusercontent.com/rdpackages/rdrobust/master/stata/rdrobust_senate.dta", clear
gen vote1 = vote + runiform()
gen margin1 = margin + runiform()
cap program drop rd_prog
program define rd_prog
syntax varlist(min=2 max=2), bw(real)
cap drop run
cap drop above
cap drop above_run_inter
gen run=`2'
gen above=(run>=0)
gen above_run_inter=above*run
reg `1' run above above_run_inter if abs(run)<`bw'
end
collect clear
local outcomes vote vote1
local running_var margin margin1
foreach x of varlist `outcomes'{
foreach y of varlist `running_var'{
collect get, tag(col[`x'] row[`y']): rd_prog `x' `y', bw(15)
}
}
collect style header colname, level(hide) title(hide)
collect style header result, level(hide)
collect layout (colname[above]#row#result[_r_b _r_se]) (col)
But I would like to add "Mean" (of the dependent var.) and "Number of observations" (used in the regression) under each regression output.
I can get the values I want using the estpost command but I would like to combine this with the table above:
Code:
local outcomes vote vote1
local running_var margin margin1
eststo clear
foreach x of varlist `outcomes'{
foreach y of varlist `running_var'{
eststo: qui estpost sum `x' if abs(`y')<15
}
}
esttab, cells("mean")

Comment