Repository navigation
Expand file tree
/
Copy pathmake.do
More file actions
353 lines (308 loc) · 11.6 KB
/
Copy pathmake.do
File metadata and controls
353 lines (308 loc) · 11.6 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
// =============================================================================
// make.do — Build script for didhetero-stata
//
// Usage:
// do make.do Compile Mata code and create ldidhetero.mlib
//
// Prerequisites:
// Working directory must be set to didhetero-stata/
// =============================================================================
// Clear memory and set working directory
clear all
set more off
// Determine package root from do-file location
local PKGROOT ""
local DOFILE `"`c(filename)'"'
if strpos(`"`DOFILE'"', "/make.do") {
local PKGROOT : subinstr local DOFILE "/make.do" "", all
}
if `"`PKGROOT'"' == "" {
local _dh_env_root : env DIDHETERO_STATA_ROOT
if `"`_dh_env_root'"' != "" {
capture confirm file "`_dh_env_root'/make.do"
if !_rc {
local PKGROOT `"`_dh_env_root'"'
}
}
}
if `"`PKGROOT'"' == "" {
capture confirm file "make.do"
if !_rc {
local PKGROOT `"`c(pwd)'"'
}
else {
capture confirm file "didhetero-stata/make.do"
if !_rc {
local PKGROOT `"`c(pwd)'/didhetero-stata"'
}
}
}
if `"`PKGROOT'"' == "" {
di as error "Cannot locate didhetero-stata root. Set DIDHETERO_STATA_ROOT or invoke make.do from the package/repo root."
exit 601
}
quietly cd "`PKGROOT'"
capture confirm file "make.do"
if _rc {
di as error "Resolved package root does not contain make.do: `PKGROOT'"
exit 601
}
// Load test environment if available
capture noisily do "tests/_dh_test_env.do"
if _rc {
capture noisily do "didhetero-stata/tests/_dh_test_env.do"
}
if _rc {
display as text "(tests/_dh_test_env.do not found — skipping QA env setup)"
local _rc 0
}
display _n "{hline 60}"
display " didhetero-stata build system"
display "{hline 60}"
// =========================================================================
// Stage 1: Clear Mata memory
// =========================================================================
display _n "Stage 1: Clearing Mata memory..."
mata: mata clear
// =========================================================================
// Stage 2: Clean old .mlib files
// =========================================================================
display "Stage 2: Cleaning old .mlib files..."
capture erase "mata/ldidhetero.mlib"
capture erase "ado/ldidhetero.mlib"
// =========================================================================
// Stage 3: Compile .mata files in dependency order
// =========================================================================
display _n "Stage 3: Compiling Mata source files..."
// Data structure definitions
display as text " Compiling: mata/didhetero_types.mata"
capture noisily do "mata/didhetero_types.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_types.mata (rc = " _rc ")"
exit _rc
}
// Unified error codes and message utilities
display as text " Compiling: mata/didhetero_errors.mata"
capture noisily do "mata/didhetero_errors.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_errors.mata (rc = " _rc ")"
exit _rc
}
// Kernel weight computation
display as text " Compiling: mata/didhetero_kernel.mata"
capture noisily do "mata/didhetero_kernel.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_kernel.mata (rc = " _rc ")"
exit _rc
}
// Utility functions (split into functional submodules)
display as text " Compiling: mata/didhetero_utils_formula.mata"
capture noisily do "mata/didhetero_utils_formula.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_utils_formula.mata (rc = " _rc ")"
exit _rc
}
display as text " Compiling: mata/didhetero_utils_numerical.mata"
capture noisily do "mata/didhetero_utils_numerical.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_utils_numerical.mata (rc = " _rc ")"
exit _rc
}
display as text " Compiling: mata/didhetero_utils_domain.mata"
capture noisily do "mata/didhetero_utils_domain.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_utils_domain.mata (rc = " _rc ")"
exit _rc
}
display as text " Compiling: mata/didhetero_utils_init.mata"
capture noisily do "mata/didhetero_utils_init.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_utils_init.mata (rc = " _rc ")"
exit _rc
}
// Local polynomial regression
display as text " Compiling: mata/didhetero_lpr.mata"
capture noisily do "mata/didhetero_lpr.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_lpr.mata (rc = " _rc ")"
exit _rc
}
// Bandwidth selection — LP regression
display as text " Compiling: mata/didhetero_bwselect_lp.mata"
capture noisily do "mata/didhetero_bwselect_lp.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_bwselect_lp.mata (rc = " _rc ")"
exit _rc
}
// Bandwidth selection — kernel density
display as text " Compiling: mata/didhetero_bwselect_kde.mata"
capture noisily do "mata/didhetero_bwselect_kde.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_bwselect_kde.mata (rc = " _rc ")"
exit _rc
}
// Kernel density estimation
display as text " Compiling: mata/didhetero_kde.mata"
capture noisily do "mata/didhetero_kde.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_kde.mata (rc = " _rc ")"
exit _rc
}
// Bandwidth selection — local polynomial density estimation
display as text " Compiling: mata/didhetero_bwselect_lpdensity.mata"
capture noisily do "mata/didhetero_bwselect_lpdensity.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_bwselect_lpdensity.mata (rc = " _rc ")"
exit _rc
}
// Estimation modules
// Generalized propensity score estimation
display as text " Compiling: mata/didhetero_gps.mata"
capture noisily do "mata/didhetero_gps.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_gps.mata (rc = " _rc ")"
exit _rc
}
// Outcome regression estimation
display as text " Compiling: mata/didhetero_or.mata"
capture noisily do "mata/didhetero_or.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_or.mata (rc = " _rc ")"
exit _rc
}
// Stage 1 estimation dispatch
display as text " Compiling: mata/didhetero_stage1.mata"
capture noisily do "mata/didhetero_stage1.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_stage1.mata (rc = " _rc ")"
exit _rc
}
// Intermediate variable construction
display as text " Compiling: mata/didhetero_intermediate.mata"
capture noisily do "mata/didhetero_intermediate.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_intermediate.mata (rc = " _rc ")"
exit _rc
}
// CATT estimation core
display as text " Compiling: mata/didhetero_catt_core.mata"
capture noisily do "mata/didhetero_catt_core.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_catt_core.mata (rc = " _rc ")"
exit _rc
}
// Stage 2 and 3 estimation
display as text " Compiling: mata/didhetero_stage23.mata"
capture noisily do "mata/didhetero_stage23.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_stage23.mata (rc = " _rc ")"
exit _rc
}
// Standard error and analytical uniform confidence band
display as text " Compiling: mata/didhetero_se.mata"
capture noisily do "mata/didhetero_se.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_se.mata (rc = " _rc ")"
exit _rc
}
// Bootstrap engine — infrastructure primitives (must precede unified)
display as text " Compiling: mata/didhetero_bootstrap_engine.mata"
capture noisily do "mata/didhetero_bootstrap_engine.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_bootstrap_engine.mata (rc = " _rc ")"
exit _rc
}
// Bootstrap unified module — application layer (depends on engine)
display as text " Compiling: mata/didhetero_bootstrap_unified.mata"
capture noisily do "mata/didhetero_bootstrap_unified.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_bootstrap_unified.mata (rc = " _rc ")"
exit _rc
}
// Legacy placeholders (consolidated into didhetero_bootstrap_unified.mata)
display as text " Compiling: mata/didhetero_bootstrap.mata (placeholder)"
capture noisily do "mata/didhetero_bootstrap.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_bootstrap.mata (rc = " _rc ")"
exit _rc
}
display as text " Compiling: mata/didhetero_boot.mata (placeholder)"
capture noisily do "mata/didhetero_boot.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_boot.mata (rc = " _rc ")"
exit _rc
}
display as text " Compiling: mata/didhetero_bootstrap_opt.mata (placeholder)"
capture noisily do "mata/didhetero_bootstrap_opt.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_bootstrap_opt.mata (rc = " _rc ")"
exit _rc
}
// Estimation orchestration
display as text " Compiling: mata/didhetero_run.mata"
capture noisily do "mata/didhetero_run.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_run.mata (rc = " _rc ")"
exit _rc
}
// Aggregation of treatment effects
display as text " Compiling: mata/didhetero_aggte.mata"
capture noisily do "mata/didhetero_aggte.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_aggte.mata (rc = " _rc ")"
exit _rc
}
// Simulated data generation
display as text " Compiling: mata/didhetero_simdata.mata"
capture noisily do "mata/didhetero_simdata.mata"
if _rc {
display as error "ERROR: Failed to compile didhetero_simdata.mata (rc = " _rc ")"
exit _rc
}
// =========================================================================
// Stage 4: Create .mlib library
// =========================================================================
display _n "Stage 4: Creating ldidhetero.mlib..."
capture noisily mata: mata mlib create ldidhetero, dir("mata") replace
if _rc {
display as error "ERROR: Failed to create ldidhetero.mlib (rc = " _rc ")"
exit _rc
}
capture noisily mata: mata mlib add ldidhetero *(), dir("mata") complete
if _rc {
display as error "ERROR: Failed to add functions to ldidhetero.mlib (rc = " _rc ")"
exit _rc
}
// =========================================================================
// Stage 5: Copy .mlib to ado/ directory
// =========================================================================
display "Stage 5: Copying .mlib to ado/ directory..."
capture noisily copy "mata/ldidhetero.mlib" "ado/ldidhetero.mlib", replace
if _rc {
display as error "ERROR: Failed to copy ldidhetero.mlib to ado/ (rc = " _rc ")"
exit _rc
}
// =========================================================================
// Stage 6: Rebuild Mata library index
// =========================================================================
display "Stage 6: Rebuilding Mata library index..."
mata: mata mlib index
// =========================================================================
// Build complete
// =========================================================================
display _n as text "{hline 50}"
display as result "Build successful!"
display as text " Library: mata/ldidhetero.mlib"
display as text " Copy: ado/ldidhetero.mlib"
display as text "{hline 50}"
// =========================================================================
// Stage 7: Test entry point removed
// =========================================================================
if "`0'" == "test" {
display as error _n "ERROR: make.do no longer accepts the test subcommand."
display as text "Build and test entry points are now decoupled."
display as text "Use an explicit runner instead, for example:"
display as text " do tests/_run_tests.do"
display as text " do tests/run_test_gps.do"
exit 198
}