-------------------------------------------------------------------------------
name: <unnamed>
log: Z:\PUBLIC_web\Stataworkshops\Postfiles\jackknife_postfile.smcl
log type: smcl
opened on: 21 Nov 2014, 10:11:30
1 . do "Z:\PUBLIC_web\Stataworkshops\Postfiles\jackknife postfile.do"
Use the automobile data set. Demonstrate the jackknife command.
2 . sysuse auto
(1978 Automobile Data)
3 . 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% Conf. 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
------------------------------------------------------------------------------
4 . jackknife coef=_b[mpg]: regress price mpg weight foreign
(running regress on estimation sample)
Jackknife replications (74)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
5 . ................................................. 50
6 . .......................
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% Conf. Interval]
-------------+----------------------------------------------------------------
coef | 21.8536 87.57669 0.25 0.804 -152.6865 196.3937
------------------------------------------------------------------------------
Produce the same results using postfile.
7 . postfile coeffs b se using "coeffs.dta", replace
(note: file coeffs.dta not found)
8 . 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. }
9 . postclose coeffs
10 . use "coeffs.dta", clear
11 . 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
12 . ci se
Variable | Obs Mean Std. Err. [95% Conf. Interval]
-------------+---------------------------------------------------------------
se | 74 74.78354 .2176474 74.34977 75.21732
end of do-file
13 . log close
name: <unnamed>
log: Z:\PUBLIC_web\Stataworkshops\Postfiles\jackknife_postfile.smcl
log type: smcl
closed on: 21 Nov 2014, 10:12:36
-------------------------------------------------------------------------------