-
Notifications
You must be signed in to change notification settings - Fork 315
/
Table 8-1-1.do
149 lines (125 loc) · 4.45 KB
/
Table 8-1-1.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
clear all
set more off
eststo clear
capture log close _all
capture version 13
/* Set random seed for replication */
set seed 42
/* Number of simulations */
local reps = 25000
/* Define program for use with -simulate- command */
capture program drop clusterbias
program define clusterbias, rclass
syntax, [sigma(real 1)]
/* Set parameters of the simulation */
local N = 30
local r = 0.9
local N_1 = `r' * 30
clear
set obs `N'
gen D = (`N_1' < _n)
gen epsilon = rnormal(0, `sigma') if D == 0
replace epsilon = rnormal(0, 1) if D == 1
gen Y = 0 * D + epsilon
/* Conventional */
regress Y D
matrix B = e(b)
local b1 = B[1, 1]
matrix C = e(V)
local conventional = sqrt(C[1, 1])
/* HC0 and HC1 */
regress Y D, vce(robust)
matrix C = e(V)
local hc0 = sqrt(((`N' - 2) / `N') * C[1, 1]) // Stata doesn't have hc0
local hc1 = sqrt(C[1, 1])
/* HC2 */
regress Y D, vce(hc2)
matrix C = e(V)
local hc2 = sqrt(C[1, 1])
/* HC3 */
regress Y D, vce(hc3)
matrix C = e(V)
local hc3 = sqrt(C[1, 1])
/* Return results from program */
return scalar b1 = `b1'
return scalar conventional = `conventional'
return scalar hc0 = `hc0'
return scalar hc1 = `hc1'
return scalar hc2 = `hc2'
return scalar hc3 = `hc3'
end
/* Run simulations */
/*----------------------*/
/* Panel A: sigma = 0.5 */
/*----------------------*/
simulate b1 = r(b1) ///
conventional = r(conventional) ///
hc0 = r(hc0) ///
hc1 = r(hc1) ///
hc2 = r(hc2) ///
hc3 = r(hc3), reps(`reps'): clusterbias, sigma(0.50)
gen max_conv_hc0 = max(conventional, hc0)
gen max_conv_hc1 = max(conventional, hc1)
gen max_conv_hc2 = max(conventional, hc2)
gen max_conv_hc3 = max(conventional, hc3)
/* Mean and standard deviations of simulation results */
tabstat *, stat(mean sd) column(stat) format(%9.3f)
/* Rejection rates */
foreach stderr of varlist conventional hc* max_*_hc* {
gen z_`stderr'_reject = (2 * normal(-abs(b1 / `stderr')) <= 0.05)
gen t_`stderr'_reject = (2 * ttail(30 - 2, abs(b1 / `stderr')) <= 0.05)
}
/* Normal */
tabstat z_*_reject, stat(mean) column(stat) format(%9.3f)
/* t-distribution */
tabstat t_*_reject, stat(mean) column(stat) format(%9.3f)
/*-----------------------*/
/* Panel B: sigma = 0.85 */
/*-----------------------*/
simulate b1 = r(b1) ///
conventional = r(conventional) ///
hc0 = r(hc0) ///
hc1 = r(hc1) ///
hc2 = r(hc2) ///
hc3 = r(hc3), reps(`reps'): clusterbias, sigma(0.85)
gen max_conv_hc0 = max(conventional, hc0)
gen max_conv_hc1 = max(conventional, hc1)
gen max_conv_hc2 = max(conventional, hc2)
gen max_conv_hc3 = max(conventional, hc3)
/* Mean and standard deviations of simulation results */
tabstat *, stat(mean sd) column(stat)
/* Rejection rates */
foreach stderr of varlist conventional hc* max_*_hc* {
gen z_`stderr'_reject = (2 * normal(-abs(b1 / `stderr')) <= 0.05)
gen t_`stderr'_reject = (2 * ttail(30 - 2, abs(b1 / `stderr')) <= 0.05)
}
/* Normal */
tabstat z_*_reject, stat(mean) column(stat) format(%9.3f)
/* t-distribution */
tabstat t_*_reject, stat(mean) column(stat) format(%9.3f)
/*--------------------*/
/* Panel C: sigma = 1 */
/*--------------------*/
simulate b1 = r(b1) ///
conventional = r(conventional) ///
hc0 = r(hc0) ///
hc1 = r(hc1) ///
hc2 = r(hc2) ///
hc3 = r(hc3), reps(`reps'): clusterbias
gen max_conv_hc0 = max(conventional, hc0)
gen max_conv_hc1 = max(conventional, hc1)
gen max_conv_hc2 = max(conventional, hc2)
gen max_conv_hc3 = max(conventional, hc3)
/* Mean and standard deviations of simulation results */
tabstat *, stat(mean sd) column(stat)
/* Rejection rates */
foreach stderr of varlist conventional hc* max_*_hc* {
gen z_`stderr'_reject = (2 * normal(-abs(b1 / `stderr')) <= 0.05)
gen t_`stderr'_reject = (2 * ttail(30 - 2, abs(b1 / `stderr')) <= 0.05)
}
/* Normal */
tabstat z_*_reject, stat(mean) column(stat) format(%9.3f)
/* t-distribution */
tabstat t_*_reject, stat(mean) column(stat) format(%9.3f)
/* End of file */
exit