Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spatial autocorrelation with fixed effects negative binomial regression

    Hi all,

    I'm examining the effect of fire occurrence on visits to National Parks and Forests using a panel dataset. Since my Y variable is a count variable, I intend to do so using a negative binomial fixed effects model. However, my units of analysis are not iid; there is spatial correlation between. I created a spatial weighting matrix on ArcMap which has 3 columns: my unit ID, neighboring unit ID, and weight. However, I'm having a hard time doing anything with it on Stata. I have two questions:

    1) When I do spmat import using "weights.dta", I keep getting errors that say "error in line 1 of file." I don't know why that's happening. Here's what's in line 1:
    realpudfid nid weight
    248 249 .2736487

    2) All I'm trying to do is cluster standard errors properly. Is it even possible to do this with a negative binomial model? Could someone walk me through how?

    Thank you so much!

  • #2
    Hi Mansi,

    Spatial models are relatively new addition to empirical research. I doubt if there exist such command like xtpoisson in spatial world. You may like to explore user written code, but I think chances are very low.
    Running spatial fixed effect is tricky. First try to find if there is any spatail autocorelation.
    Creating Spatial weight matrix for panel data in spatial model is tedious unlike in cross sectional data.

    I develop following code to make a Spatial weight matrix that suits to run fixed effect in panel data.

    clear
    import excel "PSU_Centroid.xlsx", sheet("Sheet1") firstrow
    merge 1:1 PSUNO using NLSS_2010
    keep if _merge==3
    drop _merge
    spwmatrix gecon _CY _CX, wn(knn5) knn(5) rowstand xport(knn5, txt) replace
    clear
    insheet using "knn5.txt", delimiter(" ")
    list, table clean noheader
    save KNN5.dta, replace
    outsheet using KNN5.txt, delimiter(" ") nonames nolabel replace
    drop in 1
    spmat import KNN5 using KNN5.txt, replace normalize(row)
    spmat export KNN5 using KNN5.txt, replace
    spmat save KNN5 using KNN5.spmat, replace


    Cheers,

    Harry

    Comment


    • #3
      Dear harry sharma ,

      Thank you so much, this is very helpful! So if I understand what you're saying correctly--- you're indicating that instead of using a spatial matrix imported from say ArcMap, I should generate the spatial matrix directly in Stata by using an Excel file with my polygon X and Y coordinates? What did the details of this line mean:

      spwmatrix gecon _CY _CX, wn(knn5) knn(5) rowstand xport(knn5, txt) replace?

      Thank you so much! I really appreciate it!

      Comment


      • #4
        Hi Manshi,

        You can use dta or import excel in stata. In above code in first line, I am importing excel file which has stored my X an Y coordinates. Then merging them with my actual survey data in second line. If you already have your X and Y stored in your survey data you can start from following code;

        spwmatrix gecon _CY _CX, wn(knn5) knn(5) rowstand xport(knn5, txt) replace /* spwmatrix is very useful to create tailored matrix. Here I use KNN5 which means only closest five are my neighbours. You can also create KNN10, contiguity and other matrix depending on your requirement */
        code followed after spwmatrix are to import this matrix in spmat because I am using XSMLE which only uses spmat. You can also import this matrix in spmatrix in place of spmat if you are using spatial model that uses spmatrix.

        I hope this will help you. Else you share your data sample to run this program for you.
        In statalist getting response for query related Spatial model is very difficult since this relatively new in research and very few people have expertise.

        Cheers,

        Harry

        Comment

        Working...
        X