-------------
      name:  <unnamed>
       log:  Z:\PUBLIC_web\Stataworkshops\Postfiles\jackknife_postfile.smcl
  log type:  smcl
 opened on:  21 Nov 2014, 10:11:30

. do "Z:\PUBLIC_web\Stataworkshops\Postfiles\jackknife postfile.do"

. /*
> # Markdoc demo
> Use the automobile data set.  Demonstrate the **jackknife** command.
> */
. sysuse auto
(1978 Automobile Data)

.
. regress price mpg weight foreign

      Source |       SS       df       MS              Number of obs =      74
-------------+------------------------------           F(  3,    70) =   23.29
       Model |   317252881     3   105750960           Prob > F      =  0.0000
    Residual |   317812515    70  4540178.78           R-squared     =  0.4996
-------------+------------------------------           Adj R-squared =  0.4781
       Total |   635065396    73  8699525.97           Root MSE      =  2130.8

-------------+----------------------------------------------------------------
        price |      Coef.    Std. Err.       t    P>|t|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
         mpg |     21.8536    74.22114      0.29    0.769     -126.1758      169.883
      weight |    3.464706     .630749      5.49    0.000      2.206717     4.722695
     foreign |     3673.06    683.9783      5.37    0.000      2308.909     5037.212
       _cons |   -5853.696    3376.987     -1.73    0.087     -12588.88     881.4934
-------------+----------------------------------------------------------------

. jackknife coef=_b[mpg]: regress price mpg weight foreign
(running regress on estimation sample)

Jackknife replications (74)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50
........................

Linear regression                               Number of obs      =        74
                                                Replications       =        74


command:  regress price mpg weight foreign


coef:  _b[mpg]


          n():  e(N)

-------------+----------------------------------------------------------------
             |              Jackknife
             |      Coef.    Std. Err.       t    P>|t|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
        coef |     21.8536    87.57669      0.25    0.804     -152.6865     196.3937
-------------+----------------------------------------------------------------

. /*
> Produce the same results using **postfile**.
> */
. postfile coeffs b se using "coeffs.dta", replace
(note: file coeffs.dta not found)

.
. forvalues i = 1/74 {
  2.         quietly regress price mpg weight foreign if _n~=`i'
  3.         local b _b[mpg]
  4.         local se _se[mpg]
  5.         post coeffs (`b') (`se')
  6.         }

.
. postclose coeffs

.
. use "coeffs.dta", clear

. summarize b se

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
           b |        74    21.87022    10.32004  -45.60361    44.3121
          se |        74    74.78354    1.872273   69.52323   87.14951

. ci se

    Variable |        Obs        Mean    Std. Err.       [95% Conf. Interval]
-------------+---------------------------------------------------------------
          se |         74    74.78354    .2176474        74.34977    75.21732

.
end of do-file

. log close
      name:  <unnamed>
       log:  Z:\PUBLIC_web\Stataworkshops\Postfiles\jackknife_postfile.smcl
  log type:  smcl
 closed on:  21 Nov 2014, 10:12:36
-------------