-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtable1.m
163 lines (152 loc) · 6.65 KB
/
table1.m
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
% //////////////////////////////////////////////////////////////////////
% Abbring and Salimans (2021), Table 1 (fka laplace/test.m)
% - Maximum Likelihood Estimates for Kennan’s (1985) Strike Duration
% Data
%
% dependencies: strkdur.asc mhtmle.m
% output: tab1.tex - LaTeX version of Table 1
% tab1times.tex - LaTeX code with comp times Table 1
% tab1.mat - contains structure `est` with estimates and
% corresponding llh column IV for figure4.m
% //////////////////////////////////////////////////////////////////////
%% clear screen and workspace and set seed
clear
clc
format short
rng(230681) % set seed for random starting values MHT estimation
%% read strike data
rawdata=load('strkdur.asc');
x=rawdata(:,2);
y=rawdata(:,1)/7;
%% estimation
estimates=nan(6,14);
stderrors=estimates;
loglik=nan(6,1);
comptime = [];
% Columns I-VI
for i = 1:6
fprintf('Calculating Table 1 Column %1d\n',i)
L = min(i,5); % nrunobs
Q = max(i-5,0); % nrshocks
tic;
[est,ses,llh,opt]=mhtmle(y,false,x,'point','point',L,Q);
comptime=[comptime;toc];
% last 4 arguments are: unobs_type, shock_type, nrunobs (L), nrshocks
% (Q); unobs_type and shock_type can be either 'gamma' or 'point'
% disp(opt)
if i==4
save('tab1','est','llh') % save estimates IV for Figure 4
end
loglik(i)=llh;
estimates(i,1)=est.bm_var; % sigma^2
if Q>0
estimates(i,2)=est.shock_lambda;
estimates(i,3)=est.shock_nu;
end
estimates(i,4)=est.beta; % beta
[estimates(i,5:4+L),srtidx]=sort(est.unobs_v); % v
estimates(i,10:9+L)=est.unobs_p(srtidx); % pi
stderrors(i,1)=ses.bm_var;
if Q>0
stderrors(i,2)=ses.shock_lambda;
stderrors(i,3)=ses.shock_nu;
end
stderrors(i,4)=ses.beta;
stderrors(i,5:4+L)=ses.unobs_v(srtidx);
stderrors(i,10:9+L)=ses.unobs_p(srtidx);
end
% Column VI with gamma shocks
fprintf('Calculating Table 1 Column 6 with gamma shocks\n',i)
L = 5; % nrunobs
Q = 1; % nrshocks
[est,ses,llh,opt]=mhtmle(y,false,x,'point','gamma',L,Q);
% last 4 arguments are: unobs_type, shock_type, nrunobs (L), nrshocks
% (Q); unobs_type and shock_type can be either 'gamma' or 'point'
% disp(opt)
%% Export tex file with computation times (incl macros only cited in replication doc)
f1=fopen('tab1times.tex','w');
fprintf(f1,'\\def\\gammalambda{$%.3e$}\n',est.shock_lambda);
fprintf(f1,'\\def\\gammatau{$%.3e$}\n',est.shock_rho);
fprintf(f1,'\\def\\gammaomega{$%.3e$}\n',est.shock_nu);
fprintf(f1,'\\def\\gammallh{$%6.1f$}\n',llh);
fprintf(f1,'\\def\\gammamintdivo{$%6.3f$}\n',-est.shock_rho/est.shock_nu);
fprintf(f1,'Computation times (in seconds):');
fprintf(f1,'\\begin{tabular}{cccccc}');
fprintf(f1,'I&II&III&IV&V&VI\\\\');
fprintf(f1,'$%4.1f$&$%4.1f$&$%4.1f$&$%4.1f$&$%4.1f$&$%4.1f$',comptime);
fprintf(f1,'\\end{tabular}\n');
fclose(f1);
%% Export tex file with Table 1 (incl macros estimates cited in main text)
f1=fopen('tab1.tex','w');
fprintf(f1,'\\def\\vone{$%6.1f$}\n',estimates(4,4+1));
fprintf(f1,'\\def\\vtwo{$%6.1f$}\n',estimates(4,4+2));
fprintf(f1,'\\def\\vthree{$%6.1f$}\n',estimates(4,4+3));
fprintf(f1,'\\def\\vfour{$%6.1f$}\n',estimates(4,4+4));
fprintf(f1,'%s\n','\begin{table}');
fprintf(f1,'%s\n','\caption{Maximum Likelihood Estimates for \cites{jem85:kennan} Strike Duration Data\label{table:strike}}');
fprintf(f1,'%s\n','\vspace*{0.5em}');
fprintf(f1,'%s\n','\begin{center}');
fprintf(f1,'%s\n','\small{\begin{tabular}{ccccccc}');
fprintf(f1,'%s\n','\toprule');
fprintf(f1,'%s\n','& I & II & III & IV & V & VI\tabularnewline');
fprintf(f1,'%s\n','\midrule');
fprintf(f1,'%s\n','\midrule');
fprintf(f1,'%s\n','$\mu$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ \tabularnewline');
fprintf(f1,'%s\n','& $(0)$ & $(0)$ & $(0)$ & $(0)$ & $(0)$ & $(0)$ \tabularnewline');
fprintf(f1,'%s\n','\midrule');
s=sprintf('$\\sigma^{2}$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$\\tabularnewline',...
estimates(:,1));
fprintf(f1,'%s\n',strrep(s,'NaN',''));
s=sprintf('& $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$\\tabularnewline',...
stderrors(:,1));
fprintf(f1,'%s\n',strrep(s,'( NaN)',''));
fprintf(f1,'%s\n','\midrule');
s=sprintf('$\\lambda$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$\\tabularnewline',...
estimates(:,2));
fprintf(f1,'%s\n',strrep(s,'NaN',''));
s=sprintf('& $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$\\tabularnewline',...
stderrors(:,2));
fprintf(f1,'%s\n',strrep(s,'( NaN)',''));
fprintf(f1,'%s\n','\midrule');
s=sprintf('$\\nu$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$\\tabularnewline',...
estimates(:,3));
fprintf(f1,'%s\n',strrep(s,'NaN',''));
s=sprintf('& $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$\\tabularnewline',...
stderrors(:,3));
fprintf(f1,'%s\n',strrep(s,'( NaN)',''));
fprintf(f1,'%s\n','\midrule');
s=sprintf('$\\beta$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$\\tabularnewline',...
estimates(:,4));
fprintf(f1,'%s\n',strrep(s,'NaN',''));
s=sprintf('& $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$\\tabularnewline',...
stderrors(:,4));
fprintf(f1,'%s\n',strrep(s,'( NaN)',''));
fprintf(f1,'%s\n','\midrule');
for l=1:5
s=sprintf('$v_%d$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$\\tabularnewline',...
[l;estimates(:,4+l)]);
fprintf(f1,'%s\n',strrep(s,'NaN',''));
s=sprintf('& $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$\\tabularnewline',...
stderrors(:,4+l));
fprintf(f1,'%s\n',strrep(s,'( NaN)',''));
fprintf(f1,'%s\n','\midrule');
end
for l=1:5
s=sprintf('$\\pi_%d$ & $%6.0f$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$ & $%6.3f$\\tabularnewline',...
[l;estimates(:,9+l)]);
fprintf(f1,'%s\n',strrep(s,'NaN',''));
s=sprintf('& $(%6.0f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$ & $(%6.3f)$\\tabularnewline',...
stderrors(:,9+l));
fprintf(f1,'%s\n',strrep(s,'( NaN)',''));
fprintf(f1,'%s\n','\midrule');
end
fprintf(f1,'%s\n','\midrule');
s=sprintf('$\\ell_N$ & $%6.1f$ & $%6.1f$ & $%6.1f$ & $%6.1f$ & $%6.1f$ & $%6.1f$\\tabularnewline\n',...
loglik);
fprintf(f1,'%s\n',strrep(s,'NaN',''));
fprintf(f1,'%s\n','\bottomrule');
fprintf(f1,'%s\n','\end{tabular}}');
fprintf(f1,'%s\n','\end{center}');
fprintf(f1,'%s\n','{\footnotesize Note: The drift is normalized to $1$ per week. All specifications include a single covariate, \cites{jem85:kennan} deseasonalized and detrended log industrial production. Asymptotic standard errors are in parentheses.}');
fprintf(f1,'%s\n','\end{table}');
fclose(f1);