forked from tholden/gmmtbx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
varest.m
30 lines (26 loc) · 1.01 KB
/
varest.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
% VAREST: Computes the covariance matrix, std. errors, and confidence intervals of the GMM estimators.
%
% SYNTAX: [VAR, SD, CI] = varest(D, S, theta, T)
%
% INPUT
% D : The gradient of the sample moment conditions.
% S : The long-run covariance matrix estimator.
% theta : The GMM estimates.
% T : The number os observations.
%
% OUTPUT
% VAR : The variance-covariance matrix of the estimators (size pxp, where p is the number of estimators).
% SD : The 95% standard error [ = sqrt(Var/T) ] of the estimates (px1 vector).
% CI : The 95% confidence intervals for the estimators(written in matrix form. An px2 matrix has the entries of these intervals).
function [VAR,SD,CI]=varest(D,S,theta,T);
W = inv(S);
invDWD = inv(D'*W*D);
VAR = invDWD*D'*W*S*W*D*invDWD;
SDA = diag(VAR);
SD = (1/sqrt(T))*sqrt(SDA);
[nrth,ncth] = size(theta);
CI = zeros(nrth,2);
for i=1:nrth
CI(i,1) = theta(i,1)-(1.96*sqrt(VAR(i,i))/sqrt(T));
CI(i,2) = theta(i,1)+(1.96*sqrt(VAR(i,i))/sqrt(T));
end