Actual StataMP numerical output. Log header and machine paths omitted.

. regress logacc trend i.month unem spdlaw beltlaw wkends

      Source |       SS           df       MS      Number of obs   =       108
-------------+----------------------------------   F(16, 91)       =     57.61
       Model |  1.14490873        16  .071556796   Prob > F        =    0.0000
    Residual |  .113028314        91  .001242069   R-squared       =    0.9101
-------------+----------------------------------   Adj R-squared   =    0.8943
       Total |  1.25793704       107  .011756421   Root MSE        =    .03524

------------------------------------------------------------------------------
      logacc | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
       trend |   .0011011   .0002579     4.27   0.000     .0005889    .0016133
             |
       month |
          2  |  -.0338346   .0177683    -1.90   0.060    -.0691291    .0014599
          3  |    .076953   .0167941     4.58   0.000     .0435936    .1103123
          4  |   .0104562   .0170469     0.61   0.541    -.0234053    .0443178
          5  |   .0237075   .0169389     1.40   0.165    -.0099395    .0573546
          6  |   .0219334   .0172149     1.27   0.206    -.0122619    .0561288
          7  |   .0499292   .0167036     2.99   0.004     .0167496    .0831088
          8  |   .0559523   .0168173     3.33   0.001     .0225468    .0893578
          9  |   .0420694   .0172819     2.43   0.017     .0077411    .0763977
         10  |    .081717   .0169554     4.82   0.000     .0480372    .1153968
         11  |   .0768721   .0172455     4.46   0.000     .0426161    .1111282
         12  |   .0990862   .0170705     5.80   0.000     .0651778    .1329947
             |
        unem |  -.0212173   .0033974    -6.25   0.000    -.0279659   -.0144688
      spdlaw |  -.0537593   .0126036    -4.27   0.000    -.0787948   -.0287238
     beltlaw |   .0954526    .014235     6.71   0.000     .0671765    .1237288
      wkends |   .0033333   .0037761     0.88   0.380    -.0041675    .0108342
       _cons |   10.63986   .0630859   168.66   0.000     10.51455    10.76518
------------------------------------------------------------------------------

. * END conventional
. estimates store conventional

. scalar b_ols=_b[beltlaw]

. scalar se_ols=_se[beltlaw]

. predict double residual, residuals

. * BEGIN robust
. regress logacc trend i.month unem spdlaw beltlaw wkends, vce(robust)

Linear regression                               Number of obs     =        108
                                                F(16, 91)         =      51.37
                                                Prob > F          =     0.0000
                                                R-squared         =     0.9101
                                                Root MSE          =     .03524

------------------------------------------------------------------------------
             |               Robust
      logacc | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
       trend |   .0011011   .0002676     4.12   0.000     .0005696    .0016326
             |
       month |
          2  |  -.0338346    .021402    -1.58   0.117    -.0763471    .0086779
          3  |    .076953   .0215727     3.57   0.001     .0341013    .1198046
          4  |   .0104562   .0189763     0.55   0.583    -.0272378    .0481503
          5  |   .0237075    .018758     1.26   0.210    -.0135529    .0609679
          6  |   .0219334   .0200891     1.09   0.278    -.0179711    .0618379
          7  |   .0499292   .0198585     2.51   0.014     .0104827    .0893756
          8  |   .0559523   .0193811     2.89   0.005     .0174541    .0944505
          9  |   .0420694   .0186208     2.26   0.026     .0050814    .0790574
         10  |    .081717   .0211651     3.86   0.000     .0396752    .1237588
         11  |   .0768721   .0199737     3.85   0.000     .0371969    .1165474
         12  |   .0990862    .021658     4.58   0.000     .0560653    .1421072
             |
        unem |  -.0212173   .0038238    -5.55   0.000    -.0288128   -.0136218
      spdlaw |  -.0537593   .0120059    -4.48   0.000    -.0776076    -.029911
     beltlaw |   .0954526   .0123682     7.72   0.000     .0708847    .1200206
      wkends |   .0033333   .0039443     0.85   0.400    -.0045016    .0111682
       _cons |   10.63986   .0681238   156.18   0.000     10.50454    10.77518
------------------------------------------------------------------------------

. * END robust
. scalar se_robust=_se[beltlaw]

. assert abs(_b[beltlaw]-b_ols)<1e-10

. * BEGIN hac
. newey logacc trend i.month unem spdlaw beltlaw wkends, lag(4)

Regression with Newey–West standard errors      Number of obs     =        108
Maximum lag = 4                                 F( 16,        91) =      37.42
                                                Prob > F          =     0.0000

------------------------------------------------------------------------------
             |             Newey–West
      logacc | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
       trend |   .0011011   .0003897     2.83   0.006      .000327    .0018752
             |
       month |
          2  |  -.0338346   .0168283    -2.01   0.047    -.0672619   -.0004073
          3  |    .076953   .0183367     4.20   0.000     .0405293    .1133766
          4  |   .0104562   .0176927     0.59   0.556    -.0246882    .0456006
          5  |   .0237075    .018769     1.26   0.210    -.0135748    .0609899
          6  |   .0219334   .0200354     1.09   0.277    -.0178644    .0617313
          7  |   .0499292   .0200711     2.49   0.015     .0100605    .0897979
          8  |   .0559523   .0194475     2.88   0.005     .0173223    .0945823
          9  |   .0420694   .0187812     2.24   0.028     .0047629    .0793759
         10  |    .081717    .021099     3.87   0.000     .0398064    .1236276
         11  |   .0768721   .0210425     3.65   0.000     .0350737    .1186705
         12  |   .0990862   .0241168     4.11   0.000     .0511812    .1469913
             |
        unem |  -.0212173   .0051302    -4.14   0.000    -.0314079   -.0110268
      spdlaw |  -.0537593   .0170449    -3.15   0.002    -.0876169   -.0199018
     beltlaw |   .0954526   .0188985     5.05   0.000     .0579131    .1329922
      wkends |   .0033333   .0028746     1.16   0.249    -.0023768    .0090434
       _cons |   10.63986   .0635823   167.34   0.000     10.51356    10.76616
------------------------------------------------------------------------------

. * END hac
. scalar se_hac=_se[beltlaw]

. assert abs(_b[beltlaw]-b_ols)<1e-10

. * BEGIN exact_change
. nlcom 100*(exp(_b[beltlaw])-1)

       _nl_1: 100*(exp(_b[beltlaw])-1)

------------------------------------------------------------------------------
      logacc | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       _nl_1 |   10.01567    2.07913     4.82   0.000     5.940653    14.09069
------------------------------------------------------------------------------

. * END exact_change
. * BEGIN bg
. estimates restore conventional
(results conventional are active now)

. estat bgodfrey, lags(1 4)

Breusch–Godfrey LM test for autocorrelation
---------------------------------------------------------------------------
    lags(p)  |          chi2               df                 Prob > chi2
-------------+-------------------------------------------------------------
       1     |         13.010               1                   0.0003
       4     |         16.907               4                   0.0020
---------------------------------------------------------------------------
                        H0: no serial correlation

. * END bg
. generate lag_residual=L.residual
(1 missing value generated)

. * Export the numeric Stata date; the downloadable do-file reapplies %tm.
. format month_id %9.0g

. export delimited month_id month year totacc logacc residual lag_residual trend unem spdlaw beltlaw
>  wkends using "output/traffic.csv", replace
file output/traffic.csv saved

. file open stats using "output/traffic_stats.csv", write replace

. file write stats "method,coefficient,se" _n

. file write stats "Conventional," (b_ols) "," (se_ols) _n

. file write stats "Robust," (b_ols) "," (se_robust) _n

. file write stats "HAC_4," (b_ols) "," (se_hac) _n

. file close stats

. display "ECO603_MEETING_11_COMPLETE"
ECO603_MEETING_11_COMPLETE



Actual StataMP numerical output; machine-specific log header omitted.

. * BEGIN audit
. count
  420

. summarize score str el income

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
       score |        420    654.1565    19.05335     605.55     706.75
         str |        420    19.64043    1.891812         14       25.8
          el |        420    15.76816    18.28593          0   85.53972
      income |        420    15.31659     7.22589      5.335     55.328

. count if el>20
  118

. * END audit
. * BEGIN normal_equations
. regress score str

      Source |       SS           df       MS      Number of obs   =       420
-------------+----------------------------------   F(1, 418)       =     22.58
       Model |  7794.11004         1  7794.11004   Prob > F        =    0.0000
    Residual |  144315.484       418  345.252353   R-squared       =    0.0512
-------------+----------------------------------   Adj R-squared   =    0.0490
       Total |  152109.594       419  363.030056   Root MSE        =    18.581

------------------------------------------------------------------------------
       score | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
         str |  -2.279808   .4798256    -4.75   0.000     -3.22298   -1.336637
       _cons |    698.933   9.467491    73.82   0.000     680.3231    717.5428
------------------------------------------------------------------------------

. predict double fitted, xb

. predict double residual, residuals

. generate double xu=str*residual

. summarize residual xu

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    residual |        420    6.28e-14    18.55878  -47.72669   48.54041
          xu |        420    1.23e-12     361.342  -954.3068   867.0591

. quietly summarize score

. scalar ybar=r(mean)

. generate double total_sq=(score-ybar)^2

. generate double resid_sq=residual^2

. quietly summarize total_sq, meanonly

. scalar sst=r(sum)

. quietly summarize resid_sq, meanonly

. scalar ssr=r(sum)

. display "R2 reconstructed = " %12.9f 1-ssr/sst
R2 reconstructed =  0.051240095

. assert abs(1-ssr/sst-e(r2))<1e-9

. * END normal_equations
. * BEGIN precision
. regress score str el income

      Source |       SS           df       MS      Number of obs   =       420
-------------+----------------------------------   F(3, 416)       =    334.89
       Model |  107568.862         3  35856.2873   Prob > F        =    0.0000
    Residual |  44540.7318       416  107.069067   R-squared       =    0.7072
-------------+----------------------------------   Adj R-squared   =    0.7051
       Total |  152109.594       419  363.030056   Root MSE        =    10.347

------------------------------------------------------------------------------
       score | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
         str |  -.0687755   .2769078    -0.25   0.804    -.6130885    .4755375
          el |  -.4882667   .0292832   -16.67   0.000    -.5458283   -.4307052
      income |   1.494517   .0748334    19.97   0.000     1.347418    1.641616
       _cons |   640.3155   5.774885   110.88   0.000     628.9639    651.6671
------------------------------------------------------------------------------

. scalar full_b=_b[str]

. scalar df=e(df_r)

. scalar s2=e(rss)/df

. display "Observations = " e(N) "  parameters including intercept = " e(rank)
Observations = 420  parameters including intercept = 4

. display "Residual degrees of freedom = " df "  s-squared = " s2
Residual degrees of freedom = 416  s-squared = 107.06907

. estat vif

    Variable |       VIF       1/VIF  
-------------+----------------------
      income |      1.14    0.873929
          el |      1.12    0.891206
         str |      1.07    0.931159
-------------+----------------------
    Mean VIF |      1.11

. * END precision
. * BEGIN linear_contrast
. lincom -2*str+5*el

 ( 1)  - 2*str + 5*el = 0

------------------------------------------------------------------------------
       score | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
         (1) |  -2.303783   .5903562    -3.90   0.000    -3.464236    -1.14333
------------------------------------------------------------------------------

. * END linear_contrast
. quietly regress score el income

. predict double ry, residuals

. quietly regress str el income

. predict double rx, residuals

. quietly regress ry rx, noconstant

. assert abs(_b[rx]-full_b)<1e-9

. * BEGIN sample_size
. set seed 6032711

. generate double subset_draw=runiform()

. sort subset_draw observat

. regress score str el if _n<=105, vce(robust)

Linear regression                               Number of obs     =        105
                                                F(2, 102)         =      66.11
                                                Prob > F          =     0.0000
                                                R-squared         =     0.4453
                                                Root MSE          =     14.315

------------------------------------------------------------------------------
             |               Robust
       score | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
         str |  -.1764537   .6896493    -0.26   0.799     -1.54437    1.191462
          el |  -.6936553   .0606742   -11.43   0.000    -.8140022   -.5733083
       _cons |   667.5091   14.19835    47.01   0.000     639.3467    695.6715
------------------------------------------------------------------------------

. scalar small_b=_b[str]

. scalar small_se=_se[str]

. regress score str el, vce(robust)

Linear regression                               Number of obs     =        420
                                                F(2, 417)         =     223.82
                                                Prob > F          =     0.0000
                                                R-squared         =     0.4264
                                                Root MSE          =     14.464

------------------------------------------------------------------------------
             |               Robust
       score | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
         str |  -1.101296   .4328472    -2.54   0.011     -1.95213   -.2504616
          el |  -.6497768   .0310318   -20.94   0.000     -.710775   -.5887786
       _cons |   686.0322   8.728224    78.60   0.000     668.8754     703.189
------------------------------------------------------------------------------

. scalar full_se=_se[str]

. display "Observed SE ratio (105 / 420) = " small_se/full_se
Observed SE ratio (105 / 420) = 1.5932859

. * END sample_size
. clear

. set obs 1
Number of observations (_N) was 0, now 1.

. generate double smaller_b=scalar(small_b)

. generate double smaller_se=scalar(small_se)

. generate double full_se=scalar(full_se)

. export delimited using "output/overleaf_samples.csv", replace
file output/overleaf_samples.csv saved

. 
. do "setup.do" traffic

. args dataset

. clear

. set more off

. if "`dataset'"=="schools" {
.     use "data/caschool.dta", clear
.     rename testscr score
.     rename el_pct el
.     rename avginc income
.     assert _N==420
.     assert !missing(score,str,el,income)
. }

. if "`dataset'"=="retail" {
.     use "data/retail.dta", clear
.     keep if !missing(sprice,income) & sprice>0 & income>0
.     generate double inc10=income/10000
.     generate double lp=ln(sprice)
.     generate double li=ln(income)
. }

. if "`dataset'"=="traffic" {
.     use "data/traffic.dta", clear
.     assert _N==108
.     generate month_id=ym(1981,1)+_n-1
.     format month_id %tm
.     assert year==year(dofm(month_id))
.     assert t==_n
.     generate byte month=month(dofm(month_id))
.     local m=2
.     foreach flag in feb mar apr may jun jul aug sep oct nov dec {
  2.         assert `flag'==(month==`m')
  3.         local ++m
  4.     }
.     generate double logacc=ln(totacc)
.     generate trend=_n
.     tsset month_id

Time variable: month_id, 1981m1 to 1989m12
        Delta: 1 month
. }

. if "`dataset'"=="panel" {
.     use "data/fatality.dta", clear
.     generate double fatality=10000*mrall
.     isid state year
.     xtset state year
.     assert _N==336
. }

. if "`dataset'"=="cigarettes" {
.     use "data/cig_ch12.dta", clear
.     keep if year==1995
.     generate double logq=ln(packpc)
.     generate double logp=ln(avgprs/cpi)
.     generate double salestax=(taxs-tax)/cpi
.     generate double logincome=ln(income/(pop*cpi))
.     assert _N==48
. }

. if "`dataset'"=="mortgages" {
.     use "data/hmda_sw.dta", clear
.     generate byte deny=(s7==3) if !missing(s7)
.     generate double pir=s46/100
.     assert _N==2380
.     assert !missing(deny,pir)
. }

. 
end of do-file

. * BEGIN dynamic
. regress logacc L.logacc trend i.month unem spdlaw beltlaw wkends, vce(robust)

Linear regression                               Number of obs     =        107
                                                F(17, 89)         =      67.48
                                                Prob > F          =     0.0000
                                                R-squared         =     0.9283
                                                Root MSE          =     .03179

------------------------------------------------------------------------------
             |               Robust
      logacc | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
      logacc |
         L1. |   .3326578    .090942     3.66   0.000      .151958    .5133577
             |
       trend |   .0008893   .0002165     4.11   0.000      .000459    .0013195
             |
       month |
          2  |   .0146527   .0228309     0.64   0.523    -.0307119    .0600172
          3  |   .1430085   .0236012     6.06   0.000     .0961134    .1899037
          4  |    .038098   .0182453     2.09   0.040      .001845     .074351
          5  |    .072244    .020017     3.61   0.001     .0324707    .1120174
          6  |    .062745   .0195854     3.20   0.002     .0238293    .1016607
          7  |   .0893948   .0201297     4.44   0.000     .0493976    .1293921
          8  |   .0938234   .0185598     5.06   0.000     .0569454    .1307013
          9  |   .0761947   .0175797     4.33   0.000     .0412643    .1111252
         10  |   .1188968   .0212805     5.59   0.000     .0766128    .1611807
         11  |   .0991803   .0195533     5.07   0.000     .0603283    .1380323
         12  |   .1255027    .020455     6.14   0.000      .084859    .1661464
             |
        unem |  -.0125834   .0036327    -3.46   0.001    -.0198015   -.0053653
      spdlaw |  -.0414191   .0117486    -3.53   0.001    -.0647634   -.0180748
     beltlaw |   .0652123   .0140206     4.65   0.000     .0373537    .0930709
      wkends |   .0032099   .0035067     0.92   0.362    -.0037578    .0101777
       _cons |   7.018421   .9794514     7.17   0.000     5.072272     8.96457
------------------------------------------------------------------------------

. * END dynamic
. * BEGIN diagnostics
. regress logacc trend i.month unem spdlaw beltlaw wkends

      Source |       SS           df       MS      Number of obs   =       108
-------------+----------------------------------   F(16, 91)       =     57.61
       Model |  1.14490873        16  .071556796   Prob > F        =    0.0000
    Residual |  .113028314        91  .001242069   R-squared       =    0.9101
-------------+----------------------------------   Adj R-squared   =    0.8943
       Total |  1.25793704       107  .011756421   Root MSE        =    .03524

------------------------------------------------------------------------------
      logacc | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
       trend |   .0011011   .0002579     4.27   0.000     .0005889    .0016133
             |
       month |
          2  |  -.0338346   .0177683    -1.90   0.060    -.0691291    .0014599
          3  |    .076953   .0167941     4.58   0.000     .0435936    .1103123
          4  |   .0104562   .0170469     0.61   0.541    -.0234053    .0443178
          5  |   .0237075   .0169389     1.40   0.165    -.0099395    .0573546
          6  |   .0219334   .0172149     1.27   0.206    -.0122619    .0561288
          7  |   .0499292   .0167036     2.99   0.004     .0167496    .0831088
          8  |   .0559523   .0168173     3.33   0.001     .0225468    .0893578
          9  |   .0420694   .0172819     2.43   0.017     .0077411    .0763977
         10  |    .081717   .0169554     4.82   0.000     .0480372    .1153968
         11  |   .0768721   .0172455     4.46   0.000     .0426161    .1111282
         12  |   .0990862   .0170705     5.80   0.000     .0651778    .1329947
             |
        unem |  -.0212173   .0033974    -6.25   0.000    -.0279659   -.0144688
      spdlaw |  -.0537593   .0126036    -4.27   0.000    -.0787948   -.0287238
     beltlaw |   .0954526    .014235     6.71   0.000     .0671765    .1237288
      wkends |   .0033333   .0037761     0.88   0.380    -.0041675    .0108342
       _cons |   10.63986   .0630859   168.66   0.000     10.51455    10.76518
------------------------------------------------------------------------------

. estat dwatson

Durbin–Watson d-statistic( 17,   108) =  1.200475

. estat bgodfrey, lags(1 4)

Breusch–Godfrey LM test for autocorrelation
---------------------------------------------------------------------------
    lags(p)  |          chi2               df                 Prob > chi2
-------------+-------------------------------------------------------------
       1     |         13.010               1                   0.0003
       4     |         16.907               4                   0.0020
---------------------------------------------------------------------------
                        H0: no serial correlation

. * END diagnostics
. * BEGIN arch
. estat archlm, lags(1)
LM test for autoregressive conditional heteroskedasticity (ARCH)
---------------------------------------------------------------------------
    lags(p)  |          chi2               df                 Prob > chi2
-------------+-------------------------------------------------------------
       1     |          0.350               1                   0.5540
---------------------------------------------------------------------------
         H0: no ARCH effects      vs.  H1: ARCH(p) disturbance

. * END arch
. display "ECO603_OVERLEAF_TECHNICAL_COMPLETE"
ECO603_OVERLEAF_TECHNICAL_COMPLETE

