-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.3 Predictive power.do
253 lines (180 loc) · 6.58 KB
/
4.3 Predictive power.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
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
cls
clear
set scheme s2color
set scheme s1mono
eststo clear
set graphics on
use "data\main.dta", clear
// ---------------------------------
// Timeseries setup
// ---------------------------------
drop if missing(vix) | missing(spy) | missing(yield) | missing(bond)
// business calendar doesn't include non-weekend holidays! Although regression employs casewise deletion, computing deltas will still introduce problems, thus drop missing observations beforehand
// Newey doesn't accept business calendars even though they've been around for several years now. Because dates need to be spaced perfectly evenly without missing values in the regressand and regressors, I generate a new date variable and replace missing regression variables by their lcoeffsed versions.
gen pseudodate = _n, after(date) // Pseuodate will do, bcal probably does the same
tsset pseudodate
tsfill
// dependent vars to previous if missing -- not necessary, dropped missing ones already
// replace spy = spy[_n-1] if missing(spy)
// replace vix = vix[_n-1] if missing(vix)
// replace yield = yield[_n-1] if missing(yield)
replace fomcdummy = 0 if missing(fomcdummy)
// impact vars to 0 if missing
foreach list in dl* nmf*{
foreach a of varlist `list'{
replace `a' = 0 if missing(`a')
}
}
exit
// ---------------------------------
// Impact analyses
// ---------------------------------
// PreReleaseVolatilityDrift
// impact V, regressand(V) max(10) step(1) lag
// graph export ".\img\pred\PreReleaseVolatilityDrift.png", replace
exit
// Naive tone predictions
// DO NOT COMBINE WITH ROUTINE BELOW!! Otherwise you'd control for every other naive tone in the
// prediction regressions, but I want them standalone!
local depset = "spy" // dep for dependent variable
local controls = "fomcdummy"
order dl_nettone dl_pos dl_neg dl_uncert
foreach dep in `depset'{
local deplabel: var label `dep'
local graphs = ""
graph drop _all
foreach var of varlist dl_*{
quietly impact `var', regressand(`dep') controls(`controls') keepgraph max(250) step(10)
local graphs "`graphs' `var'"
}
graph combine `graphs', iscale(0.5) title("Predicting `deplabel' with naive tone") //subtitle("Controls: `controls'")
graph export "./img/pred/`dep'ONnaive.png", replace
}
exit
// Topic-tone predictions - no tone controls
local depset = "spy" // dep for dependent variable
local controls = "fomcdummy"
local topicset = "nmfpos nmfuncert nmfnet nmfneg"
foreach dep in `depset'{
local deplabel: var label `dep'
foreach topic in `topicset'{
local graphs = ""
graph drop _all
foreach var of varlist `topic'*{
quietly impact `var', regressand(`dep') controls(`controls') keepgraph max(250) step(10)
local graphs "`graphs' `var'"
}
graph combine `graphs', iscale(0.5) title("Predicting `deplabel' with `topic'") //subtitle("Controls: `controls'")
graph export "./img/pred/`dep'ON`topic'.png", replace
}
}
exit
//---------------------------------------------
// ARCHIVE - everything below is not used, but kept for legacy
// --------------------------------------------
// Robustness test with white SEs and no fomcdummy - unambiguous matching approach
local depset = "spy" // dep for dependent variable
local controls = ""
local topicset = "nmfpos nmfuncert nmfnet nmfneg"
foreach dep in `depset'{
local deplabel: var label `dep'
foreach topic in `topicset'{
di "`topic'"
local graphs = ""
graph drop _all
foreach var of varlist `topic'*{
di "`dep' `var' `controls'"
quietly impact `var', regressand(`dep') controls(`controls') keepgraph white max(250) step(10)
local graphs "`graphs' `var'"
}
graph combine `graphs', iscale(0.5) title("Predicting `deplabel' with `topic'") //subtitle("Controls: `controls'")
graph export "./img/white/`dep'ON`topic'.png", replace
}
}
exit
// White SEs in table form - not used
local min 1
local step 50
local max 250
local regressand spy
local varlist "nmfpos*"
local controls ""
foreach topic of varlist `varlist' {
eststo clear
forvalues i = `min'(`step')`max' {
capture drop tmp
gen tmp = S`i'.F`i'.`regressand'/`regressand'
preserve
drop if fomcdummy==0
qui eststo pred`i': reg tmp `topic' `controls', r
// predict res, resid
// wntestq res
restore
}
esttab, ar2 label mtitles
}
exit
//---------------------------------------------
// STUFF BELOW USES CONTROLS - not used in thesis
// --------------------------------------------
// Topic-tone predictions - CONTROL: respective naive tone
local depset = "spy" // dep for dependent variable
local controls = "fomcdummy"
local topicset = "nmfnettone nmfuncert nmfneg nmfpos"
foreach dep in `depset'{
local deplabel: var label `dep'
foreach topic in `topicset'{
local graphs = ""
graph drop _all
foreach var of varlist `topic'*{
local naive = subinstr("`topic'","nmf","dl_",1)
di "`var' `topic' `naive'"
quietly impact `var', regressand(`dep') controls("`naive' `controls'") keepgraph
local graphs "`graphs' `var'"
}
graph combine `graphs', iscale(0.5) title("Predicting `deplabel' with `topic'") subtitle("Controls: naive tone and `controls'")
graph export "./img/pred/`dep'ON`topic'ALT.png", replace
}
}
exit
// Topic-tone predictions - CONTROL: macro trends
local depset = "spy" // dep for dependent variable
local controls = "fomcdummy interest unemployment recession"
local topicset = "nmfnettone nmfuncert nmfneg nmfpos"
foreach dep in `depset'{
local deplabel: var label `dep'
foreach topic in `topicset'{
local graphs = ""
graph drop _all
foreach var of varlist `topic'*{
di "`var' `topic' `naive'"
quietly impact `var', regressand(`dep') controls(`controls') keepgraph
local graphs "`graphs' `var'"
}
graph combine `graphs', iscale(0.5) title("Predicting `deplabel' with `topic'") subtitle("Controls: `controls'")
graph export "./img/pred/`dep'ON`topic'MACRO.png", replace
}
}
exit
// Lda stuff
// impact vix ldanettone* 500 30
// graph export ".\img\pred\ldanettoneONvix.png", replace
// impact vix ldauncert* 500 30
// graph export ".\img\pred\ldanetuncertONvix.png", replace
// Time variable handling: OLD APPROACH
// gen d_vix = vix[_n]-vix[_n-1], after(vix)
// replace d_vix = 0 if missing(d_vix)
// bcal create vix_cal, from(date) replace generate(trading_days)
// tsset trading_days
// Set dataset up as timeseries to use lag operators in regressions
// bcal create spy_cal, from(date) replace generate(trading_days)
// tsset trading_days
// foreach a of varlist dl* {
// replace `a' = `a'[_n-1] if missing(`a')
// }
// foreach a of varlist lda* {
// replace `a' = `a'[_n-1] if missing(`a')
// }
// foreach a of varlist nmf* {
// replace `a' = `a'[_n-1] if missing(`a')
// }