forked from rdpackages/rdrobust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdplot_illustration.do
52 lines (46 loc) · 3.06 KB
/
rdplot_illustration.do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
********************************************************************************
** RDROBUST Stata Package
** Do-file for RDPLOT Illustration
** Authors: Sebastian Calonico, Matias D. Cattaneo, Max H. Farrell and Rocio Titiunik
********************************************************************************
** net install rdrobust, from(https://raw.githubusercontent.com/rdpackages/rdrobust/master/stata) replace
********************************************************************************
clear all
********************************************************************************
** Load data and generate RDPLOT results without output plot
********************************************************************************
use "rdrobust_senate.dta", clear
global y vote
global x margin
global c 0
su $x
global x_min = r(min)
global x_max = r(max)
rdplot $y $x, genvars hide ci(95)
********************************************************************************
** Default RDPLOT
********************************************************************************
twoway (scatter rdplot_mean_y rdplot_mean_bin, sort msize(small) mcolor(gs10)) ///
(function `e(eq_l)', range($x_min $c) lcolor(black) sort lwidth(medthin) lpattern(solid)) ///
(function `e(eq_r)', range($c $x_max) lcolor(black) sort lwidth(medthin) lpattern(solid)), ///
xline($c, lcolor(black) lwidth(medthin)) xscale(r($x_min $x_max)) ///
legend(cols(2) order(1 "Sample average within bin" 2 "Polynomial fit of order 4" )) title("Regression function fit", color(gs0))
********************************************************************************
** RDPLOT with confidence intervals
********************************************************************************
twoway (rcap rdplot_ci_l rdplot_ci_r rdplot_mean_bin, color(gs11)) ///
(scatter rdplot_mean_y rdplot_mean_bin, sort msize(small) mcolor(gs10)) ///
(function `e(eq_l)', range($x_min $c) lcolor(black) sort lwidth(medthin) lpattern(solid)) ///
(function `e(eq_r)', range($c $x_max) lcolor(black) sort lwidth(medthin) lpattern(solid)), ///
xline($c, lcolor(black) lwidth(medthin)) xscale(r($x_min $x_max)) ///
legend(cols(2) order(1 "Sample average within bin" 2 "Polynomial fit of order 4" )) title("Regression function fit", color(gs0))
********************************************************************************
** RDPLOT with shaded confidence intervals
********************************************************************************
twoway (rarea rdplot_ci_l rdplot_ci_r rdplot_mean_bin if rdplot_id<0, sort color(gs11)) ///
(rarea rdplot_ci_l rdplot_ci_r rdplot_mean_bin if rdplot_id>0, sort color(gs11)) ///
(scatter rdplot_mean_y rdplot_mean_bin, sort msize(small) mcolor(gs10)) ///
(function `e(eq_l)', range($x_min $c) lcolor(black) sort lwidth(medthin) lpattern(solid)) ///
(function `e(eq_r)', range($c $x_max) lcolor(black) sort lwidth(medthin) lpattern(solid)), ///
xline($c, lcolor(black) lwidth(medthin)) xscale(r($x_min $x_max)) ///
legend(cols(2) order(1 "Sample average within bin" 2 "Polynomial fit of order 4" )) title("Regression function fit", color(gs0))