title: Issues with calculating moran I test for spatial autocorrelation
body: <p>I have an issue with using R to calculate the Moran I test for spatial autocorrelation. </p>
  
  <p>I did the following:</p>
  
  <pre><code>#I download all the appropriate libraries 
  
      library(maptools) 
      library(spdep) 
      library(splancs) 
      library(spatstat)
      library(pwt)
  
  #i import my shapefile and I calculate the coordinates
  serbia&lt;-readShapePoly("SRB_adm1")
  coords&lt;-coordinates(serbia)
  
  
  #i created a weigthed matrix using the above definition of neigbour(dnb60 object)
  dnb60.listw&lt;-nb2listw(dnb60,style="W", zero.policy=F)
  
  #i import my dataset which contains around 500 variables and is a firm level dataset containing 2373 firms.
  library(foreign)
  statafile&lt;-read.dta("path", missing.type = T, warn.missing.labels = T) 
  
  #i combine the shapefile(serbia) with the imported dataset(statafile) and created file with coordiantes (new) using common variable ID_1(region code). My final dataset is data_total.
  new&lt;- cbind(coordinates(serbia), serbia$ID_1)
  newdata &lt;- data.frame(new)
  names(newdata)&lt;-c("X", "Y", "ID_1")
  cis_08_10 &lt;- merge(statafile, serbia, by="ID_1", all.x=T)
  data_total&lt;-merge(cis_08_10, newdata, by="ID_1",all.x=T)
  </code></pre>
  
  <p>I am interested in the calculated Moran I test for the specific variable <code>prod_ser</code> in the final dataset <code>data_total</code>. </p>
  
  <p>I did the following: </p>
  
  <pre><code>#calculating Moran I test
  moran.test(data_total$prod_ser, dnb60.listw, randomisation=F)
  I get the following error: Error in moran.test(data_total$prod_ser, dnb60.listw, randomisation = F) : 
    objects of different length
  </code></pre>
  
  <p>Now, <code>data_total$prod_ser</code> has length 2373 and <code>dnb60.listw</code> has length 3. I think the main issue is that <code>W</code> matrix was created using the <code>serbia</code> shapefile containing 25 regions, whereas <code>prod_ser</code> variable is a firm-level variable from <code>data_total</code> having 2373 firms (which I guess should correspond to point-data, with firms being points).</p>
  
  <p>Why didn't merging datasets help? What else do I need to do to calculate Moran I without this error?</p>