sim.IV | R Documentation |
sim.IV
generates Instrument Variables (IV) for linear-in-mean SAR models using only the distribution of the network. See Propositions 1 and 2 of Boucher and Houndetoungan (2020).
sim.IV(
dnetwork,
X,
y = NULL,
replication = 1L,
power = 1L,
exp.network = FALSE
)
dnetwork |
network matrix of list of sub-network matrices, where the (i, j)-th position is the probability that i be connected to j. |
X |
matrix of the individual observable characteristics. |
y |
(optional) the endogenous variable as a vector. |
replication |
(optional, default = 1) is the number of repetitions (see details). |
power |
(optional, default = 1) is the number of powers of the interaction matrix used to generate the instruments (see details). |
exp.network |
(optional, default = FALSE) indicates if simulated network should be exported. |
Bramoulle et al. (2009) show that one can use GX
, G^2X
, ..., G^P X
as instruments for Gy
, where P
is the maximal power desired.
sim.IV
generate approximation of those instruments, based on Propositions 1 and 2 in Boucher and Houndetoungan (2020) (see also below).
The argument power
is the maximal power desired.
When Gy
and the instruments GX
, G^2X
, ..., G^P X
are not observed,
Boucher and Houndetoungan (2022) show that we can use one drawn from the distribution of the network in order to approximate Gy
, but that
the same draw should not be used to approximate the instruments. Thus, each component in the function's output gives
G1y
and G1X
computed with the same network and G2X
computed with another network, which can be used in order to approximate the instruments.
This process can be replicated several times and the argument replication
can be used to set the number of replications desired.
list of replication
components. Each component is a list containing G1y
(if the argument y
was provided), G1
(if exp.network = TRUE
), G2
(if exp.network = TRUE
) , G1X
, and
G2X
where G1
and G2
are independent draws of network from the distribution (see details).
G1y |
is an approximation of |
G1X |
is an approximation of |
G2X |
is an approximation of |
mcmcSAR
library(AER)
# Number of groups
M <- 30
# size of each group
N <- rep(50,M)
# individual effects
beta <- c(2,1,1.5)
# endogenous effects
alpha <- 0.4
# std-dev errors
se <- 2
# prior distribution
prior <- runif(sum(N*(N-1)))
prior <- vec.to.mat(prior, N, normalise = FALSE)
# covariates
X <- cbind(rnorm(sum(N),0,5),rpois(sum(N),7))
# true network
G0 <- sim.network(prior)
# normalise
G0norm <- norm.network(G0)
# simulate dependent variable use an external package
y <- CDatanet::simsar(~ X, contextual = FALSE, Glist = G0norm,
theta = c(alpha, beta, se))
y <- y$y
# generate instruments
instr <- sim.IV(prior, X, y, replication = 1, power = 1)
GY1c1 <- instr[[1]]$G1y # proxy for Gy (draw 1)
GXc1 <- instr[[1]]$G1X[,,1] # proxy for GX (draw 1)
GXc2 <- instr[[1]]$G2X[,,1] # proxy for GX (draw 2)
# build dataset
# keep only instrument constructed using a different draw than the one used to proxy Gy
dataset <- as.data.frame(cbind(y, X, GY1c1, GXc1, GXc2))
colnames(dataset) <- c("y","X1","X2","G1y", "G1X1", "G1X2", "G2X1", "G2X2")
# Same draws
out.iv1 <- ivreg(y ~ X1 + X2 + G1y | X1 + X2 + G1X1 + G1X2, data = dataset)
summary(out.iv1)
# Different draws
out.iv2 <- ivreg(y ~ X1 + X2 + G1y | X1 + X2 + G2X1 + G2X2, data = dataset)
summary(out.iv2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.