-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirf_dualband.ado
More file actions
104 lines (94 loc) · 4.03 KB
/
Copy pathirf_dualband.ado
File metadata and controls
104 lines (94 loc) · 4.03 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
capture program drop irf_dualband
program define irf_dualband
version 14
syntax , Irffile(string) Impulse(string) Response(string) ///
Irfname(string) ///
[Type(string) ///
Inner(integer 68) Outer(integer 90) ///
NORMalize ///
Title(string) Ytitle(string) Xtitle(string) ///
INNERcolor(string) OUTERcolor(string) ///
INNERalpha(integer 60) OUTERalpha(integer 40) ///
Name(string) ///
Export(string)]
if "`type'" == "" local type sirf
if "`xtitle'" == "" local xtitle "Steps"
if "`ytitle'" == "" local ytitle "Response"
if "`title'" == "" local title "`impulse' → `response'"
if "`innercolor'" == "" local innercolor "139 0 0"
if "`outercolor'" == "" local outercolor "219 149 168"
if "`name'" == "" local name "`impulse'_`response'"
local z_inner = invnormal(1 - (1 - `inner'/100)/2)
local z_outer = invnormal(1 - (1 - `outer'/100)/2)
preserve
use "`irffile'", clear
capture confirm variable `type'
if _rc {
di as error "IRF 文件没有 `type' 列"
ds *irf*
restore
exit 198
}
capture confirm variable std`type'
if _rc {
di as error "IRF 文件没有 std`type' 标准误列"
restore
exit 198
}
*--- 算 normalize 基准:impulse 对自己 step 0 的响应 ---*
local scale = 1
if "`normalize'" != "" {
quietly summarize `type' if irfname == "`irfname'" & ///
impulse == "`impulse'" & ///
response == "`impulse'" & ///
step == 0
if r(N) == 0 {
di as error "找不到 normalize 基准:`impulse' → `impulse' at step 0"
restore
exit 198
}
local scale = r(mean)
if abs(`scale') < 1e-10 {
di as error "normalize 基准值接近 0,无法 rescale"
restore
exit 198
}
di as text "Normalized by `impulse' own response at step 0 = `scale'"
}
*--- 筛选 ---*
quietly keep if irfname == "`irfname'" & ///
impulse == "`impulse'" & response == "`response'"
if _N == 0 {
di as error "找不到匹配数据"
restore
exit 198
}
sort step
quietly {
gen pe = `type' / `scale'
gen std_adj = std`type' / abs(`scale')
gen lo_inner = pe - `z_inner' * std_adj
gen up_inner = pe + `z_inner' * std_adj
gen lo_outer = pe - `z_outer' * std_adj
gen up_outer = pe + `z_outer' * std_adj
}
twoway (rarea lo_outer up_outer step, ///
color("`outercolor'%`outeralpha'") lwidth(none)) ///
(rarea lo_inner up_inner step, ///
color("`innercolor'%`inneralpha'") lwidth(none)) ///
(line pe step, lcolor(black) lwidth(medthick)) ///
(scatter pe step, mcolor(black) msymbol(Oh) msize(small) ///
mlcolor(black) mfcolor(white)), ///
yline(0, lcolor(black) lwidth(thin)) ///
legend(off) ///
title(`"`title'"', size(medium)) ///
ytitle(`"`ytitle'"') xtitle(`"`xtitle'"') ///
graphregion(color(white)) plotregion(color(white)) ///
xlabel(, grid glcolor(gs14) glpattern(dash)) ///
ylabel(, grid glcolor(gs14) glpattern(dash)) ///
name(`name',replace)
if "`export'" != "" {
graph export "`export'", replace
}
restore
end