From: J Bell on
I'm trying to use GMM estimation in matlab, with the function created by Cao Zhiguang.

I have the following code:

N=500;
sims=100;

beta=[0;1];
betaGMMn=zeros(sims,1);

for i=1:sims
X=[ones(N,1) rand(N,1)];
mu=randn(N,1);
Y=X*beta+mu;

betaGMMnorm=gmmestimation('linearmodel01',X\Y,Y,X,X,100,2);
betaGMMn(i)=betaGMMnorm(2);

end

Matlab gives the errors:
"??? Error using ==> minus
Matrix dimensions must agree.

Error in ==> linearmodel01 at 4
eta=Y-(alpha+beta*X);

Error in ==> fminsearch at 205
fv(:,1) = funfcn(x,varargin{:});

Error in ==> gmmestimation at 55
[para(:,1),fv(:,1)]=fminsearch(moment,para0,[],1,Y,X,Z,W(:,:,1));"

I tried taking the quotes off of linearmodel, and matlab gives this message:
??? Input argument "Y" is undefined.

Error in ==> linearmodel01 at 2
[T,q]=size(Y);

The code for linearmodel01 is:
function f=linearmodel01(para,num,Y,X,Z,W)
[T,q]=size(Y);
alpha=para(1);beta=para(2);
eta=Y-(alpha+beta*X);

for i=1:T
m_t(i,:)=kron(eta(i,:),Z(i,:));
end
m=mean(m_t)';
obj=m'*W*m;
if num==1
f=obj;
elseif num==2
f=m_t;
elseif num==3
f=m;
end

My question is firstly, what is the difference between having the quotes on linearmodel01 and leaving them off, and secondly, what am I doing wrong in either case?

I think Y should be defined, and it is passed to the function gmmestimation, if I understand correctly. The code for "gmmestimation" is found here: http://www.mathworks.com/matlabcentral/fileexchange/12114-gmm

thanks for any help, I know this is a complicated question

jason bell
From: Tom Lane on
> Y=X*beta+mu;
> betaGMMnorm=gmmestimation('linearmodel01',X\Y,Y,X,X,100,2);
....
> eta=Y-(alpha+beta*X);

> My question is firstly, what is the difference between having the quotes
> on linearmodel01 and leaving them off, and secondly, what am I doing wrong
> in either case?

1. If you leave the quotes off, then MATLAB tries to execute the
linearmodel01 function and pass the result into gmmestimation. You haven't
provided any arguments, so the function fails. When you put the quotes on or
pass in a function handle such as @linearmodel1, then gmmestimation receives
the function (name or handle) and can call it with arguments that it
provides.

2. You created Y from X*beta, so I suspect beta*X is not of the correct
size, and you get an error when you try to subtract it from Y.

-- Tom