Announcement

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

  • ANKETEST is unable to find the matrix

    Dear Statalists,
    I am trying to run the Anselin-Kelejian test for assessing spatial autocorrelation in my dataset. I have already generated a spatial matrix through spmat command, and I was able to save it as a .dta file and use it to run the Moran's I test through the spatgsa command. However, I am not sure I fully get the functioning of the anketest command, which I am trying to use to run the autocorrelation testl. I understand it is a post-estimation command, so I run a simple ols to do the test, but the command does not seem to find the matrix. I am not very familiar with working with matrices on Stata, but I think that the matrix is in the programme, and it is anyway stored as a .dta file in my working directory.
    Can anybody help me to get the command to find the matrix? Here I attach the series of commands and part of the output that I run from the formation of the matrix till the error messages that the system reports after using ANKETEST.

    Thank you!
    Chiara
    Code:
    *I build the matrix
    spmat contiguity Wmm using gdxy, id(id) replace normalize(minmax)
    * I save it as a .dta file
    spmat export Wmm using "Wmm.txt", noid replace
    insheet using "Wmm.txt", delim(" ") clear
    drop in 1
    save "Wmm.dta", replace
    
    *I use it to run the Moran's I test..
    .
    use "gddatabase.dta", clear
    spatwmat using "Wmm.dta", name(Ws) 
    spatgsa ln_output, weights(Ws) moran
    
    *... and it works
    Moran's I
    --------------------------------------------------------------
              Variables |    I      E(I)   sd(I)     z    p-value*
    --------------------+-----------------------------------------
              ln_output |  0.557  -0.012   0.077   7.346   0.000
    --------------------------------------------------------------
    *1-tail test
    
    *I run the regression:
    reg ln_output dummy_zones developmentzones nst ln_inv_t3 ln_fdi_t3 ln_work prd coast urban, robust
    (output omitted)
    
    *and here is the problem with the ANKETEST
    
    anketest, wname(Wmm) wfrom(Stata) model(ols)
    (11 missing values generated)
      
    Matrix Wmm not found
    r(601);
    
     anketest, wname(Wmm) wfrom(Mata) model(ols)
    (11 missing values generated)


  • #2
    use the commands as follows:

    Code:
    clear all
    use http://fmwww.bc.edu/repec/bocode/s/spregcs.dta, clear
    regress y x1 x2
    spatwmat using http://fmwww.bc.edu/repec/bocode/s/SPWcs.dta, name(W)
    anketest, wname(W) model(ols) wfrom(Stata)
    HTML Code:
    . clear all
    . use http://fmwww.bc.edu/repec/bocode/s/spregcs.dta, clear
    . regress y x1 x2
    
          Source |       SS       df       MS              Number of obs =      49
    -------------+------------------------------           F(  2,    46) =   28.39
           Model |  7423.33055     2  3711.66528           Prob > F      =  0.0000
        Residual |  6014.88661    46  130.758405           R-squared     =  0.5524
    -------------+------------------------------           Adj R-squared =  0.5329
           Total |  13438.2172    48  279.962858           Root MSE      =  11.435
    
    ------------------------------------------------------------------------------
               y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
              x1 |  -.2739317   .1031986    -2.65   0.011    -.4816598   -.0662037
              x2 |  -1.597311   .3341306    -4.78   0.000    -2.269881   -.9247407
           _cons |   68.61898   4.735484    14.49   0.000     59.08694    78.15101
    ------------------------------------------------------------------------------
    
    . spatwmat using http://fmwww.bc.edu/repec/bocode/s/SPWcs.dta, name(W)
    
    The following matrix has been created:
    
    1. Imported binary weights matrix W
       Dimension: 49x49
    
    . anketest, wname(W) model(ols) wfrom(Stata)
     
    Diagnostic tests for Spatial Dependence
     
    Tests for Spatial Autocorrelation in the OLS Model residuals
    
    +----------------------------------------+
    |            Tests |  Statistic  P-Value |
    |------------------+---------------------|
    |        Moran's_I |       1.96   0.0503 |
    |         LM_Error |       2.35   0.1255 |
    |  Robust_LM_Error |       1.41   0.2351 |
    |           LM_Lag |       1.12   0.2891 |
    |    Robust_LM_Lag |       0.19   0.6663 |
    +----------------------------------------+
    Emad A. Shehata
    Professor (PhD Economics)
    Agricultural Research Center - Agricultural Economics Research Institute - Egypt
    Email: [email protected]
    IDEAS: http://ideas.repec.org/f/psh494.html
    EconPapers: http://econpapers.repec.org/RAS/psh494.htm
    Google Scholar: http://scholar.google.com/citations?...r=cOXvc94AAAAJ

    Comment


    • #3
      Dear Emad,
      Thank you, it worked.
      C

      Comment


      • #4
        another second way is:


        Code:
        clear all
        spatwmat using http://fmwww.bc.edu/repec/bocode/s/SPWcs.dta, name(W)
        use http://fmwww.bc.edu/repec/bocode/s/spregcs.dta, clear
        regress y x1 x2
        spatdiag, weights(W)

        HTML Code:
        . clear all
        
        . spatwmat using http://fmwww.bc.edu/repec/bocode/s/SPWcs.dta, name(W)
        
        The following matrix has been created:
        
        1. Imported binary weights matrix W
           Dimension: 49x49
        
        . spatwmat using SPWcs.dta, name(W)
        
        
        The following matrix has been created:
        
        1. Imported binary weights matrix W
           Dimension: 49x49
        
        . use http://fmwww.bc.edu/repec/bocode/s/spregcs.dta, clear
        
        . regress y x1 x2
        
              Source |       SS       df       MS              Number of obs =      49
        -------------+------------------------------           F(  2,    46) =   28.39
               Model |  7423.33055     2  3711.66528           Prob > F      =  0.0000
            Residual |  6014.88661    46  130.758405           R-squared     =  0.5524
        -------------+------------------------------           Adj R-squared =  0.5329
               Total |  13438.2172    48  279.962858           Root MSE      =  11.435
        
        ------------------------------------------------------------------------------
                   y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                  x1 |  -.2739317   .1031986    -2.65   0.011    -.4816598   -.0662037
                  x2 |  -1.597311   .3341306    -4.78   0.000    -2.269881   -.9247407
               _cons |   68.61898   4.735484    14.49   0.000     59.08694    78.15101
        ------------------------------------------------------------------------------
        
        . spatdiag, weights(W)
        
        Diagnostic tests for spatial dependence in OLS regression
        
        
        Fitted model
        ------------------------------------------------------------
        y = x1 + x2
        ------------------------------------------------------------
        
        Weights matrix
        ------------------------------------------------------------
        Name: W
        Type: Imported (binary)
        Row-standardized: No
        ------------------------------------------------------------
        
        Diagnostics
        ------------------------------------------------------------
        Test                           |  Statistic    df   p-value
        -------------------------------+----------------------------
        Spatial error:                 |
          Moran's I                    |     0.645      1    0.519
          Lagrange multiplier          |     2.348      1    0.125
          Robust Lagrange multiplier   |     1.410      1    0.235
                                       |
        Spatial lag:                   |
          Lagrange multiplier          |     1.124      1    0.289
          Robust Lagrange multiplier   |     0.186      1    0.666
        ------------------------------------------------------------
        Last edited by Emad Shehata; 08 Jun 2016, 11:00.
        Emad A. Shehata
        Professor (PhD Economics)
        Agricultural Research Center - Agricultural Economics Research Institute - Egypt
        Email: [email protected]
        IDEAS: http://ideas.repec.org/f/psh494.html
        EconPapers: http://econpapers.repec.org/RAS/psh494.htm
        Google Scholar: http://scholar.google.com/citations?...r=cOXvc94AAAAJ

        Comment


        • #5
          Also, another third way is:

          Code:
          clear all
          use http://fmwww.bc.edu/repec/bocode/s/spregcs.dta, clear
          spregcs y x1 x2 , model(ols) run(ols) lmsp wmfile(http://fmwww.bc.edu/repec/bocode/s/SPWcs.dta)
          HTML Code:
          ==============================================================================
          *** Binary (0/1) Weight Matrix: 49x49 (Non Normalized)
          ------------------------------------------------------------------------------
          ==============================================================================
          * Non Spatial Regression: Model(ols) - Run(ols)
          ==============================================================================
            y = x1 + x2
          ------------------------------------------------------------------------------
           Sample Size        =          49
           Wald Test          =     56.7713   |   P-Value > Chi2(2)       =      0.0000
           F-Test             =     28.3857   |   P-Value > F(2 , 46)     =      0.0000
           R2  (R-Squared)    =      0.5524   |   Raw Moments R2          =      0.9186
           R2a (Adjusted R2)  =      0.5329   |   Raw Moments R2 Adj      =      0.9151
           Root MSE (Sigma)   =     11.4350   |   Log Likelihood Function =   -187.3772
          ------------------------------------------------------------------------------
          - R2h= 0.5524  R2h Adj=  0.5329  F-Test =   28.39 P-Value > F(2 , 46)  0.0000
          - R2v= 0.5524  R2v Adj=  0.5329  F-Test =   28.39 P-Value > F(2 , 46)  0.0000
          ------------------------------------------------------------------------------
                     y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                    x1 |  -.2739317   .1031986    -2.65   0.011    -.4816598   -.0662037
                    x2 |  -1.597311   .3341306    -4.78   0.000    -2.269881   -.9247407
                 _cons |   68.61898   4.735484    14.49   0.000     59.08694    78.15101
          ------------------------------------------------------------------------------
          
          ==============================================================================
          *** Spatial Aautocorrelation Tests                         (Model= ols)
          ==============================================================================
            Ho: Error has No Spatial AutoCorrelation
            Ha: Error has    Spatial AutoCorrelation
          ------------------------------------------------------------------------
          - GLOBAL Moran MI            =   0.1410     P-Value > Z( 1.907)   0.0565
          - GLOBAL Geary GC            =   0.7343     P-Value > Z(-2.041)   0.0412
          - GLOBAL Getis-Ords GO       =  -0.6793     P-Value > Z(-1.907)   0.0565
          ------------------------------------------------------------------------------
          - Moran MI Error Test        =   0.6445     P-Value > Z(7.838)    0.5192
          ------------------------------------------------------------------------------
          - LM Error (Burridge)        =   2.3476     P-Value > Chi2(1)     0.1255
          - LM Error (Robust)          =   1.4096     P-Value > Chi2(1)     0.2351
          ------------------------------------------------------------------------------
            Ho: Spatial Lagged Dependent Variable has No Spatial AutoCorrelation
            Ha: Spatial Lagged Dependent Variable has    Spatial AutoCorrelation
          ------------------------------------------------------------------------
          - LM Lag (Anselin)           =   1.1240     P-Value > Chi2(1)     0.2891
          - LM Lag (Robust)            =   0.1860     P-Value > Chi2(1)     0.6663
          ------------------------------------------------------------------------------
            Ho: No General Spatial AutoCorrelation
            Ha:    General Spatial AutoCorrelation
          ------------------------------------------------------------------------
          - LM SAC (LMErr+LMLag_R)     =   2.5336     P-Value > Chi2(2)     0.2817
          - LM SAC (LMLag+LMErr_R)     =   2.5336     P-Value > Chi2(2)     0.2817
          ------------------------------------------------------------------------------
          Emad A. Shehata
          Professor (PhD Economics)
          Agricultural Research Center - Agricultural Economics Research Institute - Egypt
          Email: [email protected]
          IDEAS: http://ideas.repec.org/f/psh494.html
          EconPapers: http://econpapers.repec.org/RAS/psh494.htm
          Google Scholar: http://scholar.google.com/citations?...r=cOXvc94AAAAJ

          Comment


          • #6
            Hello,

            When using anketest in a panel data setting I get an error message:

            anketest, wname(W) model(ols) wfrom(Stata)

            classdef _b_stat() in use
            (nothing dropped)
            (160 lines skipped)
            (error occurred while loading anketest.ado)
            r(310);

            Can anyone help me? Or tell another way how to test which case of spatial dependence is present?

            Thank you
            Last edited by Bastian Longer; 13 Jan 2017, 03:45.

            Comment

            Working...
            X