-
Notifications
You must be signed in to change notification settings - Fork 3
/
lf_ci_for_linear_params.m
39 lines (29 loc) · 1.5 KB
/
lf_ci_for_linear_params.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
function [cs, slack_lb, slack_ub] = lf_ci_for_linear_params( y, X, Sigma, l, lf_cv)
%% Compute the least-favorable CI from Andrews, Roth and Pakes for testing moments of the form E[Y_i - X_i delta | Z_i] <= 0, in the special case where the target parameter is l'delta
%Inputs
% y: the (scaled) sample average of Y_i (a k x 1 vector)
% X: the (scaled) sample average of X_i (a k x m vector)
% Sigma: the (scaled) estimate of E[ Var(Y_i|Z_i) ]
% l: The target parameter is l'delta
% alpha: the size of the test (e.g. 0.05 for 5% significance)
% lf_cv: The least favorable CV outputted by lf_critical_value_fn
%Outputs:
% cs: a two-dimensional vector with the lower and upper bounds of the
% confidence set
% slack_lb: the slackness of the moments at the lb bound of the cs
% slack_ub: the slackness of the moments at the ub bound of the cs
%Notes
% If y and X are sample averages, Sigma should be E[ Var(Y|X) ] /N
% If Sigma is E[ Var(Y|X) ], then y and X should be averages scaled by sqrt(N)
% Sigma used here should be the same as the sigma used for lf_cv
sigma = sqrt(diag(Sigma));
A = -X;
b = lf_cv * sigma - y;
[delta_lb,lb] = linprog(l , A, b, [], [], [], [], optimoptions('linprog','TolFun', 10^(-8), 'Display','off')) ;
[delta_ub,ub] = linprog(-l, A, b, [], [], [], [], optimoptions('linprog','TolFun', 10^(-8), 'Display','off'));
ub = -ub; %Need to take negative of the minimum to get the max
cs = [lb; ub];
%Compute slack at upper and lower bound solutions
slack_lb = A * delta_lb - b;
slack_ub = A * delta_ub - b;
end