%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Data generation for SUR model
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%let's do 3 equations for illustration
rand('state',37); % set arbitrary seed for uniform draws
randn('state',37); % set arbitrary seed for normal draws
% generate data
%%%%%%%%%%%%%%%%%%%%%%%%%
n=1000; % set sample size
M=3; %number of equations
%first equation
%%%%%%%%%%%%%%%%%%%%%%%
x1=ones(n,1);
x2= -1.4+randn(n,1);
x3= 3+2*randn(n,1);
X1=[x1 x2 x3];
k1=size(X1,2);
b1true=[1.2 0.4 0.8]'; % "true" coefficients
%second equation
%%%%%%%%%%%%%%%%%%%%%%%
x1=ones(n,1);
x2= 4+2*randn(n,1);
X2=[x1 x2];
k2=size(X2,2);
b2true=[1.8 -0.3]'; % "true" coefficients
%third equation
%%%%%%%%%%%%%%%%%%%%%%%
x1=ones(n,1);
x2= 2+1.6*randn(n,1);
x3= -4+1.5*randn(n,1);
X3=[x1 x2 x3];
k3=size(X3,2);
b3true=[0.8 1 -0.6]'; % "true" coefficients
% VCOV for errors (our "E")
Etrue=[1 0.4 0.7;0.4 1 0.6;0.7 0.6 0.8]; %make sure this is pos. def - can be tricky...
mu=zeros(M,1);
e=mvnrnd(mu,Etrue,n); % will be n by M
e1=e(:,1);
e2=e(:,2);
e3=e(:,3);
y1=X1*b1true+e1;
y2=X2*b2true+e2;
y3=X3*b3true+e3;
save c:\klaus\AAEC6564\mlab\worksp\sur_data y1 y2 y3 X1 X2 X3 b1true...
b2true b3true Etrue y1 y2 y3;
'ok' %just so we know the script has executed