I am trying to make a table of RD estimates while displaying the mean (of the dependent variable) and number of observations (of the RD sample) under each RD estimate. I have managed to build the table with the RD estimates but am unable to add the latter under the estimates. This is the sample code:
This is the table output:
I would like the table to look like this instead:
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()
collect clear
local outcomes vote vote1
local running_var margin margin1
foreach x of varlist `outcomes'{
foreach y of varlist `running_var'{
collect get e(tau_cl) e(se_tau_cl), tag(col[`x'] row[`y']): rdrobust `x' `y' if -15<=`y' & `y'<=15
collect get r(mean) r(se), tag(col[`x'] row[`y']): su `x' if -15<=`y' & `y'<=15
}
}
collect style column, dups(center)
collect style cell result[tau_cl], nformat(%9.2f) halign(center)
collect style cell result[se_tau_cl], nformat(%9.3f) halign(center)
collect style cell result[mean], nformat(%9.2f) halign(center)
collect style cell result[N], nformat(%9.0f) halign(center)
collect style header result, level(hide)
collect layout (row#result) (col)
HTML Code:
---------------------
| vote vote1
--------+------------
margin | 12.53 12.42
| 2.869 2.908
margin1 | 7.10 7.26
| 2.864 2.861
---------------------
HTML Code:
---------------------
| vote vote1
--------+------------
margin | 12.53 12.42
| 2.869 2.908
mean | x x
N | x x
margin1 | 7.10 7.26
| 2.864 2.861
mean | x x
N | x x
---------------------

Comment