[R-sig-Geo] Help to calculate the impacts using the spreg function in sphet package: GMM/IV with one endogenous and one instrument

Roger Bivand Roger@B|v@nd @end|ng |rom nhh@no
Mon May 4 16:01:52 CEST 2020


On Mon, 4 May 2020, Roger Bivand wrote:

> On Sat, 2 May 2020, André M. Marques via R-sig-Geo wrote:
>
>>  Dear all,
>>  I apologize for my previous unclear code in the mail list.Now I hope to be
>>  clear about the problem I am facing in the following example:
>>
>>  require("sf", quietly=TRUE)library(sphet)library(spatialreg)
>>  columbus <- st_read(system.file("shapes/columbus.shp",
>>  package="spData")[1], quiet=TRUE)require("spdep", quietly=TRUE)col.gal.nb
>>  <- spdep::read.gal(system.file("weights/columbus.gal",
>>  package="spData")[1])listw <- spdep::nb2listw(col.gal.nb)
>>  # I have one endongenous (HOVAL) and one instrument (PLUMB) ## endo=~HOVAL
>>  ; instruments=~PLUMB
>>
>>  res.spreg <- spreg(CRIME ~ INC + OPEN, columbus,
>>  listw,endo=~HOVAL,lag.instr =
>>  TRUE,instruments=~PLUMB,model=c('ivhac'),het=TRUE,HAC=FALSE)
>>  class(res.spreg)#[1] "sphet"  "gstsls"summary(res.spreg)
>>  Now the problem: I'm unable to calculate the impacts and their p-values in
>>  a (cross-section) Cliff-Ord model based on GMM/IV:
>> 
>
> Had you followed list rules and posted plain text, things might have been 
> clearer. HTML tries to make code look like a paragraph of text, so messes 
> everything up. This is a plain-text version:
>
> library(sphet)
> library(spatialreg)
> columbus <- sf::st_read(system.file("shapes/columbus.shp",
>  package="spData")[1], quiet=TRUE)
> col.gal.nb <- spdep::read.gal(system.file("weights/columbus.gal",
>  package="spData")[1])
> listw <- spdep::nb2listw(col.gal.nb)
> res.spreg <- spreg(CRIME ~ INC + OPEN, columbus, listw, endo=~HOVAL,
>   lag.instr = TRUE, instruments=~PLUMB, model=c('ivhac'), het=TRUE,
>   HAC=FALSE)
> class(res.spreg)
> summary(res.spreg)
> impacts(res.spreg, listw=listw)
>
> This indicates a mismatch firstly between released spatialreg and spdep in 
> handling impacts for some sphet objects, and further that the IV case may not 
> yet be covered. Please provide this reproducible example on 
> https://github.com/r-spatial/spatialreg/issues and ping the sphet maintainer.

There was a mismatch in declaration of method imports. Try:

install.packages("sphet", repos="http://R-Forge.R-project.org")
remotes::install_github("r-spatial/spatialreg")

if it posssible for you to install packages from source; the example was 
helpful in making progress. If you can install the fresh package versions, 
please also report whether the underlying  problem is resolved on your 
real data.

Roger

>
> Roger
>
>
>>  W <- as(listw, "CsparseMatrix")trMatc <- trW(W, type="mult")trMC <- trW(W,
>>  type="MC")
>>  set.seed(1234)impacts(res.spreg, listw=listw)
>> #  I get the error message:Error in spatialreg::intImpacts(rho = rho, beta 
>> #  = beta, P = P, n = n,  :   argumento "evalues" ausente, sem padrãoAlém 
>> #  disso: Warning message:Function intImpacts moved to the spatialreg 
>> #  package
>> #  or even when I try:library(coda)lobjIQ5 <- impacts(res.spreg, tr=trMatc, 
>> #  R=200, Q=5)summary(lobjIQ5, zstats=TRUE, short=TRUE)# I got the same 
>> #  error message.
>>  ## When I use the 'evalues' argument as the vector of eigenvalues of
>>  spatial weights matrix:
>>  ev <- eigenw(listw)impacts(res.spreg, evalues=ev)
>>  # Even in this way I got the same error message.
>>
>>  Thanks for help.
>>  Best wishes,
>>  André M. Marques
>>  Federal University of ParaibaGraduate Program of Economics
>> 
>>
>>   [[alternative HTML version deleted]]
>>
>>  _______________________________________________
>>  R-sig-Geo mailing list
>>  R-sig-Geo using r-project.org
>>  https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> 
>
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: Roger.Bivand using nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en


More information about the R-sig-Geo mailing list