function[Bhat,Dhat]=fimlst(B,D,Omega,T,k1,k2) % NOTE you must have the likeli.m file in the same folder for code to % work!!! % k1 is the number of uknowns in the B matrix % k2 is the number of unknowns in the D matrix which is assumed to be % diagonal % T is the sample size % Omega is the matrix from first stage VAR % B is the matrix where the unknowns must be specified in advance. For % example, suppose B=[1 -b12;-b21 1]. In the standard recursive var we % assume that b12=0 thus b21 is the unknown. We then specify the B matrix % as B=@(x)[1 0;x(1) 1]; Recall D is assumed to be diagonal so that we % specify it as D=@(x)[x(1) 0;0 x(2)]. For this example k1=1 k2=2; For the % order condition, we have to make sure that the number of unknowns in D % which is n and number of unknowns in B does not exceed n(n+1)/2. For our % example, n=2 so k1+k2=3 so that we are just identified. n=size(Omega,2); %out=fminsearch(@(x)likeli(B,D,Omega,T,k1,x),[ones(1,k1+k2)]); %out=ga(@(x)likeli(B,D,Omega,T,k1,x),k1+k2); out=patternsearch(@(x)likeli(B,D,Omega,T,k1,x),[ones(1,k1+k2)]); Dhat=D(out(k1+1:k1+k2)); Bhat=B(out(1:k1)); save Dhat Dhat save Bhat Bhat