I am using Stata's new collect commands to produce a customized table of diff-in-diff results. I want the table to show the pre means with standard errors (SEs), the post means with SEs, and finally the diff-in-diff estimates and confidence intervals (CIs). Below is a working example almost producing the desired table.
Code:
use "http://fmwww.bc.edu/repec/bocode/c/CardKrueger1994.dta", clear collect clear * Estimate and collect regression results collect create reg1, replace collect, name(reg1): diff fte, t(treated) p(t) cov(bk kfc roys) collect create reg2, replace collect, name(reg2): diff fte, t(treated) p(t) cov(bk kfc roys) kernel id(id) * Combine regression output and create the table collect combine regs = reg1 reg2 collect addtags treat[0], fortags(result[mean_c0 se_c0 mean_c1 se_c1]) collect addtags treat[1], fortags(result[mean_t0 se_t0 mean_t1 se_t1]) collect addtags treat[2], fortags(result[diff0 se_d0 diff1 se_d1]) collect label levels treat 0 "Control" 1 "Treated" 2 "Diff (T-C)", modify collect addtags time[1], fortags(result[mean_c0 mean_t0 se_c0 se_t0 diff0 se_d0]) collect addtags time[2], fortags(result[mean_c1 mean_t1 se_c1 se_t1 diff1 se_d1]) collect addtags time[3], fortags(colname[_diff]#result[_r_b]) collect addtags time[3], fortags(result[_r_ci]) collect label levels time 1 "Pre" 2 "Post" 3 "Pre-Post" collect addtags values[1], fortags(result[mean_c0 mean_t0 mean_c1 mean_t1 diff0 diff1] colname[_diff]#result[_r_b]) collect addtags values[2], fortags(result[se_c0 se_t0 se_c1 se_t1 se_d0 se_d1] colname[_diff]#result[_r_ci]) collect addtags treat[3], fortags(time[3]#colname[_diff]#result[_r_b]) collect addtags treat[3], fortags(result[_r_ci]) collect label levels treat 3 "Diff-in-Diff", modify collect label levels collection reg1 "Social disconnection Scale (1-5)" reg2 "Social disconnection scale (1-5)" collect style cell values[1], nformat(%3.2f) halign(center) collect style cell values[2], nformat(%3.2f) sformat("(%s)") halign(center) collect style cell result[_r_ci], cidelimiter(,) nformat(%3.2f) sformat("(%s)") halign(center) collect style header values, level(hide) collect style column, dups(center) width(equal) collect style cell border_block, border(right, pattern(nil)) collect style cell cell_type[column-header]#time[1] cell_type[column-header]#time[2], border(bottom, pattern(single)) collect style cell cell_type[column-header]#time[3] cell_type[column-header]#treat, halign(center) collect layout (collection#values) (time#treat)
HTML Code:
Collection: regs Rows: collection#values Columns: time#treat Table 1: 4 x 7 ----------------------------------------------------------------------------------------------- Pre Post Pre-Post ----------------------------------------------------------------------------- Control Treated Diff (T-C) Control Treated Diff (T-C) Diff-in-Diff ----------------------------------------------------------------------------------------------- Reg1 21.16 18.84 -2.32 18.76 19.37 0.61 2.94 (1.14) (0.85) (1.03) (1.16) (0.85) (1.04) Reg2 20.04 17.07 -2.98 17.45 17.57 0.12 3.10 (0.67) (0.67) (0.94) (0.67) (0.67) (0.95) -----------------------------------------------------------------------------------------------
Code:
collect addtags treat[3], fortags(result[_r_ci])
HTML Code:
(0 items changed in collection regs)
0 Response to Customizing a Diff-in-Diff table using Collect: A question about tagging confidence intervals
Post a Comment