-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_wald.m
33 lines (31 loc) · 1.07 KB
/
get_wald.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
function [cil,ciu] = get_wald(delta_hat,x,occurrence,n,level,comp)
% Inputs
% delta_hat: 1st stage estimator
% x: support of covariates
% occurrence: outcome frequency
% n: sample size
% level: nominal level
% comp: component of interest (=1)
beta_null = [0, 0];
[zdelta, ~] = compute_z_all(beta_null, x, delta_hat);
deltablock = [zdelta(1,:).*zdelta(1,:); zdelta(1,:).*zdelta(2,:);...
zdelta(2,:).*zdelta(1,:); zdelta(2,:).*zdelta(2,:)];
deltablock = deltablock * occurrence / n;
I_delta2 = reshape(deltablock, 2, 2);
I_delta2 = get_sigmatilde(I_delta2); % regularize using Andrews & Barwic
Sigma = inv(I_delta2);
c = norminv(1-level/2,0,1);
cil = delta_hat(comp)-c*sqrt(Sigma(comp,comp)/n);
ciu = delta_hat(comp)+c*sqrt(Sigma(comp,comp)/n);
end
function SigmaTilde = get_sigmatilde(Sigma)
% Inputs:
% Sigma: Covariance matrix
% SigmaTilde: Regularized covariance matrix using Andrews & Barwick's
% method
sh_param = 0.05;
sigma = sqrt(diag(Sigma));
Omega = Sigma./(sigma*sigma');
D = diag(diag(Sigma));
SigmaTilde = Sigma + max(sh_param-det(Omega),0).*D;
end