Page 1 of 1

Dubin 1998 Replication

Posted: Thu Apr 16, 2015 1:02 pm
by CharlieEVIEWS
This code replicates part of Dubin (1998) - Spatial Econometrics, A Primer. The .txt attachment is the values of their (simulated) distance matrix (to check for congruence of results). Please feel free to post any questions below and I'll do my best to answer.

Charlie

Code: Select all

''This is a file to replciate the first half (SEM part) of Dubin (1998) in JoHE
%cd = Change your CD here
'Set up the distance matrix
wfcreate(wf=durbinreplication) u 1
matrix(10,10) distance
distance.read {%cd}\durbindistance.txt
!lamda1 = 0.33
!lamda2 = 0.67
for !l = 1 to 2
   for !p = 1 to 3
      matrix(@rows(distance),@columns(distance)) w_{!p}_{!l}
      for !a = 1 to @rows(w_{!p}_{!l})
         for !b = !a to @rows(w_{!p}_{!l})
            if !a<>!b then
               w_{!p}_{!l}(!a,!b)=1/distance(!a,!b)^(!p)
               w_{!p}_{!l}(!b,!a)=w_{!p}_{!l}(!a,!b)      
            endif
         next
      next
      for !a = 1 to @rows(w_{!p}_{!l})
         !temp = @csum(@transpose((w_{!p}_{!l})))(!a)
         for !b = 1 to @rows(w_{!p}_{!l})
            if !a<>!b then
               w_{!p}_{!l}(!a,!b)=w_{!p}_{!l}(!a,!b)/!temp
            endif
         next
      next
      matrix V_{!p}_{!l}   = @inverse(@identity(10)-(!lamda{!l}*w_{!p}_{!l}))*@inverse(@identity(10)-(!lamda{!l}*(@transpose(w_{!p}_{!l}))))
      matrix(@rows(V_{!p}_{!l}),@columns(V_{!p}_{!l})) C_{!p}_{!l}
      for !a = 1 to @rows(C_{!p}_{!l})
         for !b = !a to @rows(C_{!p}_{!l})   
            C_{!p}_{!l}(!a,!b)=V_{!p}_{!l}(!a,!b)/@sqrt(V_{!p}_{!l}(!a,!a)*V_{!p}_{!l}(!b,!b))
         next
      next   
      matrix(((@rows(C_{!p}_{!l})-1)*@rows(C_{!p}_{!l}))/2,2) output_matrix_{!p}_{!l}
      !c = 0
      for !a = 1 to @rows(C_{!p}_{!l})
         for !b = !a to @rows(C_{!p}_{!l})
            if !a<>!b then
               !c = !c+1
               output_matrix_{!p}_{!l}(!c,2)=C_{!p}_{!l}(!a,!b)
               output_matrix_{!p}_{!l}(!c,1)=distance(!a,!b)
            endif
         next
      next
      freeze(output_graph_{!p}_{!l}) output_matrix_{!p}_{!l}.scat
      show output_graph_{!p}_{!l}
   next
next