Skip to Main Content

Methods Matter: Improving causal Inference in Educational and Social Science Research by Richard J. Murnane and John B. Willett Chapter 9: Estimating Causal Effects Using a Regression-Discontinuity Approach | Stata Textbook Examples

use https://stats.idre.ucla.edu/stat/stata/examples/methods_matter/chapter9/angrist, clear

Descriptive statistics for the all variables. The variable
read
is the average reading score for each school, size is the
cohort size for each school, intended_classsize is the average
intended class size for each school, and observed_classize is the
average of actual class sizes for each school. Note: this output does not appear in the text.

sum read size intended_classize observed_classize 

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
        read |      2019    74.37917     7.67846       34.8      93.86
        size |      2019    77.74195    38.81073          8        226
intended_c~e |      2019    30.95594    6.107924          8         40
observed_c~e |      2019    29.93512    6.545885          8         44
	

A boxplot showing the distribution of read by size. (Not shown in text.)

graph box read if size>=36 & size<=46, over(size) yscale(range(20,100))

Image ch9_a-1
	

Table 9.1 on page 168.

table size if size>=36 & size<=46, contents(freq mean intended_classize ///
	mean observed_classize mean read sd read)

--------------------------------------------------------------------------------
size of   |
september |
enrollmen |
t cohort  |        Freq.  mean(inte~e)  mean(obse~e)    mean(read)      sd(read)
----------+---------------------------------------------------------------------
       36 |            9            36       27.4444      67.30444      12.36389
       37 |            9            37       26.2222      68.94066      8.497515
       38 |           10            38          33.1        67.854      14.03826
       39 |           10            39          31.2         68.87      12.07238
       40 |            9            40       29.8889      67.92847      7.865053
       41 |           28          20.5       22.6786       73.6767      8.766867
       42 |           25            21          23.4       67.5956      9.302938
       43 |           24          21.5        22.125      77.17644      7.466089
       44 |           17            22       24.4118       72.1616      7.712399
       45 |           19          22.5       22.7368      76.91684      8.708218
       46 |           20            23         22.55      70.30814      9.783914
--------------------------------------------------------------------------------
	

Difference analysis discussed on page 172.

gen small=0 if size<=40
(1724 missing values generated)

replace small=1 if size>=41
(1724 real changes made)

ttest read if size==40 | size==41, by(small)

Two-sample t test with equal variances
------------------------------------------------------------------------------
   Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
---------+--------------------------------------------------------------------
       0 |       9    67.92847    2.621684    7.865053    61.88285    73.97408
       1 |      28     73.6767    1.656782    8.766867    70.27726    77.07613
---------+--------------------------------------------------------------------
combined |      37    72.27848    1.448589    8.811421     69.3406    75.21635
---------+--------------------------------------------------------------------
    diff |           -5.748229    3.283494               -12.41408    .9176183
------------------------------------------------------------------------------
    diff = mean(0) - mean(1)                                      t =  -1.7506
Ho: diff = 0                                     degrees of freedom =       35

    Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
 Pr(T < t) = 0.0444         Pr(|T| > |t|) = 0.0888          Pr(T > t) = 0.9556
 	

Difference of difference analysis, discussed starting on page 173. (Output not shown in text.)

keep if size>=38 & size<=41
(1962 observations deleted)

recode size (38=1) (39=2) (40=3) (41=4), into(group)
(57 differences between size and group)

tabstat read, statistics(count mean var) columns(statistics) nototal by(group)

Summary for variables: read
     by categories of: group (RECODE of size (size of september enrollment cohort))

   group |         N      mean  variance
---------+------------------------------
       1 |        10    67.854  197.0727
       2 |        10     68.87  145.7423
       3 |         9  67.92847  61.85906
       4 |        28   73.6767  76.85795
----------------------------------------


graph box read, over(group)

Image ch9_b-1

* "larger" distinguishes the group with the larger enrollment in any pair.
recode group (1 3=0) (2 4=1), into(larger)
(57 differences between group and larger)

* "first" distinguishes the groups that participate in the first diff.
recode group (1 2=0) (3 4=1), into(first)
(57 differences between group and first)

* Create the two-way interaction of predictors "first" and "larger."
gen first_by_larger=first*larger

regress read first large first_by_larger 

      Source |       SS       df       MS              Number of obs =      57
-------------+------------------------------           F(  3,    53) =    1.34
       Model |  429.340264     3  143.113421           Prob > F      =  0.2709
    Residual |  5655.37182    53  106.705129           R-squared     =  0.0706
-------------+------------------------------           Adj R-squared =  0.0180
       Total |  6084.71208    56  108.655573           Root MSE      =   10.33

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       first |   .0744654   4.746224     0.02   0.988    -9.445254    9.594184
      larger |      1.016   4.619635     0.22   0.827    -8.249814    10.28181
first_by_l~r |    4.73223   6.083424     0.78   0.440    -7.469574    16.93403
       _cons |     67.854   3.266575    20.77   0.000     61.30208    74.40592
------------------------------------------------------------------------------
	

The last model can also be estimated using the factor variable syntax
introduced in Stata 11 (shown below).

regress read first##large 

      Source |       SS       df       MS              Number of obs =      57
-------------+------------------------------           F(  3,    53) =    1.34
       Model |  429.340264     3  143.113421           Prob > F      =  0.2709
    Residual |  5655.37182    53  106.705129           R-squared     =  0.0706
-------------+------------------------------           Adj R-squared =  0.0180
       Total |  6084.71208    56  108.655573           Root MSE      =   10.33

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     1.first |   .0744654   4.746224     0.02   0.988    -9.445254    9.594184
    1.larger |      1.016   4.619635     0.22   0.827    -8.249814    10.28181
             |
first#larger |
        1 1  |    4.73223   6.083424     0.78   0.440    -7.469574    16.93403
             |
       _cons |     67.854   3.266575    20.77   0.000     61.30208    74.40592
------------------------------------------------------------------------------
	

Figure 9.1 on page 176. The dataset has changed so you will
need to open the original dataset again.

use https://stats.idre.ucla.edu/stat/stata/examples/methods_matter/chapter9/angrist, clear 
recode size (36=1) (37=2)(38=3) (39=4) (40=5) (41=6), into(group)
bysort group: egen mread = mean(read)

twoway (scatter mread size if size>=36 & size<=40, c(l)) ///
    (lfit mread size if size>=36 & size<=40) ///
    (scatter mread size if size==41), ///
    legend(off)

Image ch9_1a
	

Table 9.3 on page 180.

gen small = 0
replace small=1 if size>=41
(1724 real changes made)

gen csize=size-41

regress read csize small if size>=36 & size<=41

      Source |       SS       df       MS              Number of obs =      75
-------------+------------------------------           F(  2,    72) =    2.55
       Model |  530.144127     2  265.072063           Prob > F      =  0.0848
    Residual |  7473.05836    72  103.792477           R-squared     =  0.0662
-------------+------------------------------           Adj R-squared =  0.0403
       Total |  8003.20248    74  108.151385           Root MSE      =  10.188

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       csize |   .1239759   1.068103     0.12   0.908    -2.005248      2.2532
       small |   5.120126   4.004709     1.28   0.205    -2.863115    13.10337
       _cons |   68.55657   3.511526    19.52   0.000     61.55647    75.55667
------------------------------------------------------------------------------
	

Boxplot of read by school size, for classes size 36-46. (Not shown in text.)

graph box read if size>=36 & size<=46, medtype(line) over(size) ylabel(30(10)90)


Image ch9_c-1
	

Table 9.4 on page 183.

regress read csize small if size>=36 & size<=46

      Source |       SS       df       MS              Number of obs =     180
-------------+------------------------------           F(  2,   177) =    4.25
       Model |  794.774151     2  397.387075           Prob > F      =  0.0158
    Residual |  16564.0336   177   93.582111           R-squared     =  0.0458
-------------+------------------------------           Adj R-squared =  0.0350
       Total |  17358.8078   179  96.9765798           Root MSE      =  9.6738

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       csize |   .1706798   .4360008     0.39   0.696     -.689749    1.031109
       small |   3.847157   2.811246     1.37   0.173    -1.700718    9.395031
       _cons |   68.69569   1.917758    35.82   0.000     64.91107     72.4803
------------------------------------------------------------------------------

Syntax to produce the coefficients from small and csize shown in Table 9.5 on page 184.

regress read csize small if size>=36 & size<=41

      Source |       SS       df       MS              Number of obs =      75
-------------+------------------------------           F(  2,    72) =    2.55
       Model |  530.144127     2  265.072063           Prob > F      =  0.0848
    Residual |  7473.05836    72  103.792477           R-squared     =  0.0662
-------------+------------------------------           Adj R-squared =  0.0403
       Total |  8003.20248    74  108.151385           Root MSE      =  10.188

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       csize |   .1239759   1.068103     0.12   0.908    -2.005248      2.2532
       small |   5.120126   4.004709     1.28   0.205    -2.863115    13.10337
       _cons |   68.55657   3.511526    19.52   0.000     61.55647    75.55667
------------------------------------------------------------------------------

regress read csize small if size>=36 & size<=46

      Source |       SS       df       MS              Number of obs =     180
-------------+------------------------------           F(  2,   177) =    4.25
       Model |  794.774151     2  397.387075           Prob > F      =  0.0158
    Residual |  16564.0336   177   93.582111           R-squared     =  0.0458
-------------+------------------------------           Adj R-squared =  0.0350
       Total |  17358.8078   179  96.9765798           Root MSE      =  9.6738

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       csize |   .1706798   .4360008     0.39   0.696     -.689749    1.031109
       small |   3.847157   2.811246     1.37   0.173    -1.700718    9.395031
       _cons |   68.69569   1.917758    35.82   0.000     64.91107     72.4803
------------------------------------------------------------------------------

regress read csize small if size>=35 & size<=47

      Source |       SS       df       MS              Number of obs =     221
-------------+------------------------------           F(  2,   218) =    4.24
       Model |  766.655274     2  383.327637           Prob > F      =  0.0156
    Residual |   19694.937   218  90.3437476           R-squared     =  0.0375
-------------+------------------------------           Adj R-squared =  0.0286
       Total |  20461.5923   220  93.0072375           Root MSE      =  9.5049

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       csize |   .0170745   .3139066     0.05   0.957    -.6016057    .6357547
       small |   4.121728   2.504124     1.65   0.101    -.8136644    9.057121
       _cons |   68.76637   1.673521    41.09   0.000     65.46802    72.06472
------------------------------------------------------------------------------

regress read csize small if size>=34 & size<=48

      Source |       SS       df       MS              Number of obs =     259
-------------+------------------------------           F(  2,   256) =    4.76
       Model |  827.844689     2  413.922344           Prob > F      =  0.0093
    Residual |  22239.4219   256  86.8727416           R-squared     =  0.0359
-------------+------------------------------           Adj R-squared =  0.0284
       Total |  23067.2665   258  89.4080099           Root MSE      =  9.3206

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       csize |    .001822   .2487631     0.01   0.994    -.4880608    .4917047
       small |   4.011786   2.306075     1.74   0.083    -.5295061    8.553079
       _cons |   68.98158   1.517615    45.45   0.000     65.99298    71.97018
------------------------------------------------------------------------------

regress read csize small if size>=33 & size<=49

      Source |       SS       df       MS              Number of obs =     288
-------------+------------------------------           F(  2,   285) =    4.36
       Model |  727.973263     2  363.986632           Prob > F      =  0.0136
    Residual |   23778.047   285   83.431744           R-squared     =  0.0297
-------------+------------------------------           Adj R-squared =  0.0229
       Total |  24506.0203   287  85.3868303           Root MSE      =  9.1341

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       csize |  -.0128245      .2102    -0.06   0.951    -.4265659     .400917
       small |   3.671866   2.158492     1.70   0.090    -.5767427    7.920475
       _cons |   69.54772    1.40849    49.38   0.000     66.77536    72.32008
------------------------------------------------------------------------------

regress read csize small if size>=32 & size<=50

      Source |       SS       df       MS              Number of obs =     315
-------------+------------------------------           F(  2,   312) =    4.08
       Model |   662.42455     2  331.212275           Prob > F      =  0.0178
    Residual |  25337.7997   312  81.2108965           R-squared     =  0.0255
-------------+------------------------------           Adj R-squared =  0.0192
       Total |  26000.2242   314  82.8032619           Root MSE      =  9.0117

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       csize |   .0278539   .1812721     0.15   0.878    -.3288164    .3845243
       small |   2.966343   2.040808     1.45   0.147    -1.049143    6.981828
       _cons |   70.37797   1.324983    53.12   0.000     67.77094      72.985
------------------------------------------------------------------------------

regress read csize small if size>=31 & size<=51

      Source |       SS       df       MS              Number of obs =     352
-------------+------------------------------           F(  2,   349) =    4.58
       Model |  760.140166     2  380.070083           Prob > F      =  0.0109
    Residual |  28979.7433   349  83.0365137           R-squared     =  0.0256
-------------+------------------------------           Adj R-squared =  0.0200
       Total |  29739.8834   351  84.7290126           Root MSE      =  9.1124

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       csize |   .0359248   .1544304     0.23   0.816    -.2678066    .3396562
       small |   2.927194   1.942864     1.51   0.133    -.8940006    6.748388
       _cons |   70.38686   1.252796    56.18   0.000     67.92288    72.85084
------------------------------------------------------------------------------

regress read csize small if size>=30 & size<=52

      Source |       SS       df       MS              Number of obs =     385
-------------+------------------------------           F(  2,   382) =    3.91
       Model |  632.406083     2  316.203041           Prob > F      =  0.0209
    Residual |   30914.618   382  80.9283194           R-squared     =  0.0200
-------------+------------------------------           Adj R-squared =  0.0149
       Total |  31547.0241   384  82.1537086           Root MSE      =   8.996

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       csize |  -.0441598   .1337116    -0.33   0.741    -.3070626     .218743
       small |   3.362028   1.841883     1.83   0.069    -.2594699    6.983525
       _cons |   70.28562   1.183283    59.40   0.000     67.95906    72.61219
------------------------------------------------------------------------------

regress read csize small if size>=29 & size<=53

      Source |       SS       df       MS              Number of obs =     423
-------------+------------------------------           F(  2,   420) =    3.10
       Model |  523.199711     2  261.599855           Prob > F      =  0.0459
    Residual |  35406.0265   420  84.3000631           R-squared     =  0.0146
-------------+------------------------------           Adj R-squared =  0.0099
       Total |  35929.2262   422  85.1403465           Root MSE      =  9.1815

------------------------------------------------------------------------------
        read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       csize |  -.1391658   .1191144    -1.17   0.243    -.3733004    .0949688
       small |   3.953146    1.79961     2.20   0.029      .415783     7.49051
       _cons |    70.1188   1.151217    60.91   0.000     67.85593    72.38166
------------------------------------------------------------------------------