Announcement

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

  • Creating weight matrix with spmat and spweightxt. Importing weight matrix from Geoda to Stata

    To whom it may concern, please consider that post.

    I am stata new user who have stata 16.1 and want to compute panel spatial weight matrix. I am french speaking. I will be grateful for your indulgence.

    I have 3 questions:

    1) I have read the Stata Journal (2013) 13, Number 2, pp. 242–286, Creating and managing spatial-weighting matrices with the spmat command, written by David M. Drukker and all, StataCorp, (it is a google free download). I want to use spmat commands with stata 16.1 to compute all kind of spatial weight matrices but the code shp2dta using does not run. Can anyone help me with a spmat do.file and tell me how to use it in stata 16.1 to compute spatial weight matrix?


    2) I have read "SPWEIGHTXT: Stata module to compute Panel Spatial Weight Matrix," written by Emad Abd Elmessih Shehata, 2011 (it is a google free download) but I do not have a do file. Can anyone help me with a spweightxt do.file and tell me how to use it in stata 16.1 to compute spatial weight matrix?

    3) Can anyone explain me how to import from Geoda a spatial weight matrix with gal extension to stata?

    Thank you in advance for your gratitude.


    Vedrij Elysabeth BOSSALE



  • #2
    Welcome to Statalist. You'll benefit from reading the STATA SPATIAL AUTOREGRESSIVE MODELS REFERENCE MANUAL (in particular the introductory material as well as the entry for spxtregress).

    I would ignore both questions 1 and 2 because there are now official Stata commands (as of version 15 I believe) that accomplish what's outlined there. Please take some time to read through the introductory material in the link above. I've not used geodata, but here's an example using one of the datasets that hopefully will help you get started (please use this in a do file and not interactively in the window).

    Code:
    clear all
    
    !curl -L "https://s3.amazonaws.com/geoda/data/baltimore.zip" > "baltimore.zip"
    unzipfile "baltimore.zip"
    
    cd baltimore
    spshape2dta "baltim" , replace
    
    
    use "baltim", clear
    
    spmatrix create idistance W, replace
    regress PRICE SQFT NROOM AGE
    estat moran, errorlag(W)
    
    spregress PRICE SQFT NROOM AGE, gs2sls dvarlag(W)
    estat impact
    Code:
    use "baltim", clear
    
    .
    . spmatrix create idistance W, replace
    
    . regress PRICE SQFT NROOM AGE
    
          Source |       SS           df       MS      Number of obs   =       211
    -------------+----------------------------------   F(3, 207)       =     40.45
           Model |  43246.1217         3  14415.3739   Prob > F        =    0.0000
        Residual |  73775.7197       207  356.404443   R-squared       =    0.3696
    -------------+----------------------------------   Adj R-squared   =    0.3604
           Total |  117021.841       210  557.246864   Root MSE        =    18.879
    
    ------------------------------------------------------------------------------
           PRICE |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
            SQFT |   1.124152   .2175843     5.17   0.000     .6951869    1.553118
           NROOM |    3.64891   1.522826     2.40   0.017     .6466733    6.651146
             AGE |  -.4242276   .0660516    -6.42   0.000    -.5544477   -.2940076
           _cons |   19.63938   6.425996     3.06   0.003     6.970595    32.30817
    ------------------------------------------------------------------------------
    
    . estat moran, errorlag(W)
    
    Moran test for spatial dependence
             Ho: error is i.i.d.
             Errorlags:  W
    
             chi2(1)      =    32.41
             Prob > chi2  =   0.0000
    
    .
    . spregress PRICE SQFT NROOM AGE, gs2sls dvarlag(W)
      (211 observations)
      (211 observations (places) used)
      (weighting matrix defines 211 places)
    
    Spatial autoregressive model                    Number of obs     =        211
    GS2SLS estimates                                Wald chi2(4)      =     123.67
                                                    Prob > chi2       =     0.0000
                                                    Pseudo R2         =     0.3761
    
    ------------------------------------------------------------------------------
           PRICE |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    PRICE        |
            SQFT |    1.13688   .2167932     5.24   0.000     .7119729    1.561786
           NROOM |    3.78428   1.525589     2.48   0.013     .7941793     6.77438
             AGE |  -.4191629   .0660092    -6.35   0.000    -.5485385   -.2897873
           _cons |    23.6853   8.968951     2.64   0.008     6.106475    41.26412
    -------------+----------------------------------------------------------------
    W            |
           PRICE |   -.121965   .1901585    -0.64   0.521    -.4946689    .2507389
    ------------------------------------------------------------------------------
    Wald test of spatial terms:          chi2(1) = 0.41       Prob > chi2 = 0.5213
    
    . estat impact
    
    progress   : 33%  67% 100%
    
    Average impacts                                 Number of obs     =        211
    
    ------------------------------------------------------------------------------
                 |            Delta-Method
                 |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    direct       |
            SQFT |   1.137047   .2168719     5.24   0.000     .7119855    1.562108
           NROOM |   3.784835   1.526047     2.48   0.013     .7938375    6.775833
             AGE |  -.4192244   .0659968    -6.35   0.000    -.5485758   -.2898731
    -------------+----------------------------------------------------------------
    indirect     |
            SQFT |  -.1200271   .1708123    -0.70   0.482     -.454813    .2147588
           NROOM |  -.3995287   .6003789    -0.67   0.506     -1.57625    .7771923
             AGE |   .0442535   .0612009     0.72   0.470     -.075698     .164205
    -------------+----------------------------------------------------------------
    total        |
            SQFT |    1.01702   .2438795     4.17   0.000     .5390244    1.495015
           NROOM |   3.385306   1.400309     2.42   0.016      .640752    6.129861
             AGE |  -.3749709   .0901772    -4.16   0.000     -.551715   -.1982268
    ------------------------------------------------------------------------------

    Comment


    • #3
      Justin Blasongame, thank you very much for your contribution.

      In panel spatial econometrics, there is a cohort of 6 spatial econometric models using panel data.

      In particular, there is global and local models.

      Estimates steps are:

      1) OLS panel model.

      2) Spatial Weight Matrice

      3) Tests of spatial autocorrelation( Lagrange Multiplier - LMERR and LMLAG).

      4) Computing of global models ( SARAR (p, q) or (SAC), SAR, SDM)

      5) Computing of local models (SEM, SLX and SDEM)

      6) Computing of selection tests such as Hausman test, AIC, and so on to choose the correct model specification.


      Would you mind providing me with an example and complete do.file of these 6 steps?

      Stata users your different contributions are welcome.

      Regards,

      Vedrij Elysabeth
      Last edited by Vedrij BOSSALE; 06 Jun 2020, 16:43.

      Comment

      Working...
      X