%Code to calculate spatial effects and delta method standard errors for CBD Paper
%Srinivas "Chinnu" Parinandi
%11/2012

%%Spatial effects for increases in Xs or E in Texas on other states
I=xlsread('C:\Users\cparinan\Desktop\CBDSpatialEffectsErrors\IdentityMatrix.xlsx')
Wrn=xlsread('C:\Users\cparinan\Desktop\CBDSpatialEffectsErrors\1977RN.xlsx')
Wpp=xlsread('C:\Users\cparinan\Desktop\CBDSpatialEffectsErrors\1977PP.xlsx')
rhorn=0.45*Wrn
rhopp=0.12*Wpp
SW=rhorn+rhopp
estcf1=I-SW
d_cf_beta1=inv(estcf1)
ShockX=xlsread('C:\Users\cparinan\Desktop\CBDSpatialEffectsErrors\1977TXShockX.xlsx')
TXXonothers=d_cf_beta1*ShockX
xlswrite('C:\Users\cparinan\Desktop\CBDSpatialEffectsErrors\TXXShockonothers.xls',TXXonothers)
ShockE=xlsread('C:\Users\cparinan\Desktop\CBDSpatialEffectsErrors\1977TXShockE.xlsx')
TXEonothers=d_cf_beta1*ShockE
xlswrite('C:\Users\cparinan\Desktop\CBDSpatialEffectsErrors\TXEShockonothers.xls',TXEonothers)

%Delta method standard errors for spatial effects
%For spatial effects from 10pt. shock in pcrecip variable
estcfpcrecip=1.14*d_cf_beta1
d_cf_rhorn=estcfpcrecip*Wrn*d_cf_beta1
d_cf_rhopp=estcfpcrecip*Wpp*d_cf_beta1
d_cf_rhorn40=d_cf_rhorn(:,40)
d_cf_rhopp40=d_cf_rhopp(:,40)
d_cf_betapcrecip40=d_cf_beta1(:,40)
rrb=[d_cf_rhorn40,d_cf_rhopp40,d_cf_betapcrecip40]
rrbt=rrb'
VCVM=xlsread('C:\Users\cparinan\Desktop\CBDSpatialEffectsErrors\VCVM.xlsx')
deltapcrecip=rrb*VCVM*rrbt
%prime diagonal on deltapcrecip shows standard errors for TX shock on each
%unit
%[9,9] is Georgia and [8,8] is Florida
xlswrite('C:\Users\cparinan\Desktop\CBDSpatialEffectsErrors\TXXothersError.xls',deltapcrecip)

%For spatial effects from 5pt. shock in Y-variable or error
estcfshockE=5*d_cf_beta1
d_cf_rhornE=estcfshockE*Wrn*d_cf_beta1
d_cf_rhoppE=estcfshockE*Wpp*d_cf_beta1
d_cf_rhornE40=d_cf_rhornE(:,40)
d_cf_rhoppE40=d_cf_rhoppE(:,40)
d_cf_betaE40=d_cf_beta1(:,40)
rrbE=[d_cf_rhornE40,d_cf_rhoppE40,d_cf_betaE40]
rrbtE=rrbE'
deltaE=rrbE*VCVM*rrbtE
%Same interpretation on delta matrix as before
xlswrite('C:\Users\cparinan\Desktop\CBDSpatialEffectsErrors\TXEothersError.xls',deltaE)