-
Notifications
You must be signed in to change notification settings - Fork 29
/
test.do
130 lines (105 loc) · 4.79 KB
/
test.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
noi cscript "ivreg2 with absorb()" adofile reghdfe
* Setup
sysuse auto
replace turn = . in 1 // ensure we detect MVs in absorb()
* Test 1: ivreg2==ivreghdfe
ivreg2 price weight (gear=length)
storedresults save benchmark e()
ivreghdfe price weight (gear=length)
storedresults compare benchmark e(), exclude(macro: cmd cmdline ivreg2cmd)
storedresults drop benchmark
* Test 2: ivreghdfe==ivreg+partial
ivreg2 price weight i.turn , partial(i.turn) small
**predict double xb1, xb // xb not supported with partial() (and ,resid crashed)
storedresults save benchmark e()
ivreghdfe price weight, absorb(turn) keepsingletons
assert e(N) == 73
assert e(df_m)==1
loc excluded ///
macro: cmd cmdline ivreg2cmd insts inexog partial partial1 partialcons df_m predict ///
scalar: partialcons df_m
storedresults compare benchmark e(), exclude(`excluded') tol(1e-12)
storedresults drop benchmark
**predict double xb2, xb
**_vassert xb1 xb2, tol(1e-8)
**drop xb1 xb2
* Test 3: ivreghdfe==reghdfe
reghdfe price weight, absorb(turn) keepsingletons nocons
loc bench_r2 = e(r2_within)
storedresults save benchmark e()
ivreghdfe price weight, absorb(turn) keepsingletons
assert e(rank)==.
assert e(df_m)==1
assert abs(e(r2) - `bench_r2') < 1e-8
loc excluded ///
macro: cmd cmdline vce indepvars title title2 footnote estat_cmd predict marginsnotok ///
scalar: rank ic N_hdfe_extended redundant tss tss_within mss ll_0 r2_a_within sumweights ///
r2_a r2_within r2 report_constant converged
storedresults compare benchmark e(), tol(1e-12) exclude(`excluded')
storedresults drop benchmark
// why does mss differs??
* Test 4: ivreghdfe==reghdfe with TWFE and TWC
* PART 1) Variance matches reghdfe v3
reghdfe price weight, absorb(turn foreign) cluster(turn trunk) keepsingletons version(3)
loc bench_r2 = e(r2_within)
storedresults save benchmark e()
ivreghdfe price weight, absorb(turn foreign) cluster(turn trunk) keepsingletons
assert e(rank)==.
assert e(df_m)==1
assert abs(e(r2) - `bench_r2') < 1e-8
loc included scalar: N matrix: b V
storedresults compare benchmark e(), tol(1e-12) include(`included')
storedresults drop benchmark
// why does mss and rmse differ?
* Test 4: ivreghdfe==reghdfe with TWFE and TWC
* PART 2) All else but variance match reghdfe v5 or v6
reghdfe price weight, absorb(turn foreign) cluster(turn trunk) keepsingletons nocons
loc bench_r2 = e(r2_within)
storedresults save benchmark e()
ivreghdfe price weight, absorb(turn foreign) cluster(turn trunk) keepsingletons
assert e(rank)==.
assert e(df_m)==1
assert abs(e(r2) - `bench_r2') < 1e-8
loc excluded ///
macro: cmd cmdline vce indepvars title title2 footnote estat_cmd predict title3 marginsnotok ///
scalar: rank ic N_hdfe_extended redundant tss tss_within mss ll_0 r2_a_within sumweights ///
r2_a r2_within r2 rmse N_clustervars report_constant F converged ///
matrix: V
storedresults compare benchmark e(), tol(1e-12) exclude(`excluded')
storedresults drop benchmark
// why does mss and rmse differ?
* BUGBUG: maybe tweak the small sample adjustment to match v5 and v6??
* Test 4b: as 4 but drop singletons
reghdfe price weight, absorb(turn foreign) cluster(turn trunk) nocons
loc bench_r2 = e(r2_within)
storedresults save benchmark e()
ivreghdfe price weight, absorb(turn foreign) cluster(turn trunk)
assert e(rank)==.
assert e(df_m)==1
assert abs(e(r2) - `bench_r2') < 1e-8
loc excluded ///
macro: cmd cmdline vce indepvars title title2 footnote estat_cmd predict title3 marginsnotok ///
scalar: rank ic N_hdfe_extended redundant tss tss_within mss ll_0 r2_a_within sumweights ///
r2_a r2_within r2 rmse N_clustervars report_constant F converged matrix: V
storedresults compare benchmark e(), tol(1e-12) exclude(`excluded')
storedresults drop benchmark
// why does mss and rmse differ?
* Test 5: ivreghdfe with IV
reghdfe price weight (gear=length), absorb(turn) cluster(trunk) keepsingletons version(3)
loc bench_r2 = e(r2_within)
storedresults save benchmark e()
ivreghdfe price weight (gear=length), absorb(turn) cluster(trunk) keepsing
assert e(rank)==.
assert e(df_m)==2
assert abs(e(r2) - `bench_r2') < 1e-8
* Have to add a bunch more because I' comparing against the old reghdfe
loc excluded ///
macro: cmd cmdline vce indepvars title title2 footnote estat_cmd predict title3 ///
instruments endogvars vcesuite dofadjustments subcmd ivreg2cmd marginsok marginsnotok ///
scalar: rank ic N_hdfe_extended redundant tss tss_within mss ll_0 r2_a_within sumweights ///
r2_a r2_within r2 rmse N_clustervars partial_ct df_m savestages r2u r2c G1 M1_nested ///
M1_exact K1 M1 unclustered_df_r partialcons M_due_to_nested mobility report_constant converged
storedresults compare benchmark e(), tol(1e-12) exclude(`excluded')
storedresults drop benchmark
// why does mss and rmse differ?
exit