%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sample selection model with door-to-door data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The data for this exercise flow from a door-to-door fundraising campaign conducted in
% Pitt County, North Carolina, during the fall of 2005.
% The details of this field experiment are described in Landry et al. (QJE, 2006).
% Forty-three solicitors interacted with an average of 39 households for a total sample size
% of 1682 observations.
% All observations are based on actual interactions, i.e. the "door didn't open" cases
% are not considered in this data set. The focus of this research was on the effect of lottery
% designs and solicitor attributes on donation outcomes.
% There are four possible treatments (or "institutions"), as shown in the table below.
% Each solicitor administered a single treatment,
% i.e. the treatment remained the same for a given solicitor across all interactions.
% Each respondent (or "household") is visited only once,
% so there are no multiple observations per household in the data.
tic; % start stop watch
rand('state',37); % set arbitrary seed for uniform draws
randn('state',37); % set arbitrary seed for normal draws
% load c:\klaus\AAEC6564\mlab\worksp\door2door.txt;
% data=door2door;
% clear door2door;
% save c:\klaus\AAEC6564\mlab\worksp\door2door;
% 'ok'
% break
load c:\klaus\AAEC6564\mlab\worksp\door2door;
% Open log file
[fid]=fopen('c:\Klaus\AAEC6564\mlab\logs\mod9_select_door2door.txt','w');
if fid==-1;
warning('File could not be opened');
else;
disp('File opened successfully');
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% prepare data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Variable
%
% 1 solid solicitor ID
% 2 donate "1"=donation recieved
% 3 amount donation amount
% 4 sol_f "1"=sol=female
% 5 sol_nw "1"=sol=non-white
% 6 height sol height (inches)
% 7 bmi sol body mass index (>28=overweight)
% 8 beauty beauty index (z-score)
% 9 spunk spunk index (low=-40, high=40)
% 10 res_f "1"=resident = female
% 11 res_nw "1"=resident = non-white
% 12 res_old "1"=resident=60 or older
% 13 hh_size avg. HH size in census block
% 14 perc_own %homes owned in census block
% 15 inc000 median census tract income ($1000)
% 16 lottery "1" solicitation included a lottery incentive
% 43 solicitors, each contacted on average 39.3 residents, for a total
% sample size of 1690
y = data(:,3)/10; %outcome variable
n=length(y); %1690 obs
X1=[ones(n,1) data(:,4:9) data(:,13:16)];% participation equation, 11 var's
X2=[ones(n,1) data(:,4:12) data(:,16)];% outcome equation
% Contents of X1
% 1 constant
% 2 sol_f "1"=sol=female
% 3 sol_nw "1"=sol=non-white
% 4 height sol height (inches)
% 5 bmi sol body mass index (>28=overweight)
% 6 beauty beauty index (z-score)
% 7 spunk spunk index (low=-40, high=40)
% 8 hh_size avg. HH size in census block
% 9 perc_own %homes owned in census block
% 10 inc000 median census tract income ($1000)
% 11 lottery "1" solicitation included a lottery incentive
% Contents of X2
% 1 constant
% 2 sol_f "1"=sol=female
% 3 sol_nw "1"=sol=non-white
% 4 height sol height (inches)
% 5 bmi sol body mass index (>28=overweight)
% 6 beauty beauty index (z-score)
% 7 spunk spunk index (low=-40, high=40)
% 8 res_f "1"=resident = female
% 9 res_nw "1"=resident = non-white
% 10 res_old "1"=resident=60 or older
% 11 lottery "1" solicitation included a lottery incentive
% so we use the neighborhood characteristics hh_size, perc_own, and inc000
% as added regressors in the 1st equ. for identification
k1=size(X1,2);
k2=size(X2,2);
k=k1+k2;
m=2; % number of equations
X=cell(n,1);
for i=1:n
X{i}=[X1(i,:) zeros(1,k2); zeros(1,k1) X2(i,:)];
end
k1=size(X1,2);
k2=size(X2,2);
k=k1+k2;
%generate Xi and collect as separate matrices
X=cell(n,1);
for i=1:n
X{i}=[X1(i,:) zeros(1,k2); zeros(1,k1) X2(i,:)];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% starting values, priors, and tuners
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% general elements
r1=30000; % burn-ins
r2=20000; % keepers
R=r1+r2;
% generic OLS
bols1=inv(X1'*X1)*X1'*y;
bols2=inv(X2'*X2)*X2'*y;
clear X1 X2;
% elements for beta
% note: no need to distinguish between coefficients across the two
% equations at this point
mu0=zeros(k,1); %diffuse prior for mean of betas
V0=eye(k)*100; % diffuse prior for varcov of beta
betadraw=[bols1;bols2];
% elements for E
% E will be 2 by 2
v0=m; % number of equations
S0=eye(m); % So these are the diffusest priors possible for the IW
Edraw=iw_sig11(v0,inv(S0),1); % use Nobile's (2000) contrained IW draws-routine
% elements for y1star (participation) and y2star (outcome)
% elements for y1star (participation) and y2star (amount)
f=find(y==0); % zero amount
g=find(y~=0); % positive amount
nf=length(f); % number of zero cases
ng=length(g); % number of >0 cases
l0=-inf*ones(nf,1); %lower truncation point for zero cases
r0=zeros(nf,1);% upper truncation point for zero cases
lpos=zeros(ng,1);% lower truncation point for positive amounts
rpos=inf*ones(ng,1);%upper truncation point for positive amount
y1draw = y;
y2draw = y;
ydraw=[y1draw y2draw];
[betamat,Emat]=gs_select(X,k1,k,m,n,r1,r2,mu0,V0,betadraw,v0,S0,Edraw,...
f,g,nf,ng,l0,r0,lpos,rpos,ydraw);
'GS done'
% put all draws together & run diagnostics
allmat=[betamat;Emat];
kdiag=klausdiagnostics_greater0(allmat);
fprintf(fid,'total number of iterations =\t%6.0f \n',R);
fprintf(fid,'burn-in iterations =\t%6.0f \n',r1);
fprintf(fid,'\n');
% beta stuff
out=kdiag(1:k,:)';
fprintf(fid,'Output table for betas \n\n');
fprintf(fid,'mean\t\tstd\t\tp(>0)\t\tnse\t\tIEF\t\tm*\t\tcd\n\n');
fprintf(fid,'%6.3f\t%6.3f\t%6.3f\t%6.3f\t%6.3f\t%6.3f\t%6.3f\n',out);
fprintf(fid,'\n');
out=kdiag(k+1:end,:)';
fprintf(fid,'Output table for E \n\n');
fprintf(fid,'mean\t\tstd\t\tp(>0)\t\tnse\t\tIEF\t\tm*\t\tcd\n\n');
fprintf(fid,'%6.3f\t%6.3f\t%6.3f\t%6.3f\t%6.3f\t%6.3f\t%6.3f\n',out);
fprintf(fid,'\n');
save c:\klaus\AAEC6564\mlab\worksp\select_door2door betamat Emat;
finish = toc/60;
fprintf(fid,'Time elapsed in minutes \n\n');
fprintf(fid,'%6.3f\n',finish);
st=fclose(fid);
if st==0;
disp('File closed successfully');
else;
warning('Problem with closing file');
end;