%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Data for switching regression model
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rand('state',37); % set arbitrary seed for uniform draws
randn('state',37); % set arbitrary seed for normal draws
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% data generation
% follow KPT p. 229
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n=5000; %sample size
m=3; % number of correlated equations
Etrue=[1 0.7 0.9;0.7 1 0.6;0.9 0.6 1]; %error varcov, with a "healthy" covariance term
mu=zeros(m,1); % error mean
beta1true=[0.5]'; %coefficients for selection equation
beta2true=[1]';%coefficients for "0" outcome equation
beta3true=[2]';%coefficients for "1" outcome equation
X1=[randn(n,1)];
X2=[ones(n,1)];
X3=[ones(n,1)];
e=mvnrnd(mu,Etrue,n); % will be n by 2
%latent variables
y1=X1*beta1true+e(:,1);
y2=X2*beta2true+e(:,2);
y3=X3*beta3true+e(:,3);
f=find(y1<0);
fi=length(f)/n % stop at 50%censoring
save c:\klaus\AAEC6564\mlab\worksp\switch_data;