-
Notifications
You must be signed in to change notification settings - Fork 4
/
R19_Direct_Indirect_Effects.R
102 lines (101 loc) · 2.85 KB
/
R19_Direct_Indirect_Effects.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#### Impacts - direct and indirect effects (spillovers)
#### using
#### Spatial lag model
#### Spatial Durbin model
#
#
#
# Data, data description & plots
library(ggplot2) # install.packages("ggplot2")
library(spdep) # install.packages("spdep")
library(spatialreg)
rm(list=ls())
CE_data <- read.csv("datasets/NUTS2_data.csv")
# head(CE_data, 15)
# tail(CE_data, 10)
# plot(CE_data[ , c(4:7)])
#
#
# Data description:
#
# U_pc_2012 Dependent variable, the general rate of unemployment
# for a NUTS2 region i at time t (2012)
# EUR_HAB_EU_2011 region’s GDP per capita (current EUR prices of 2011)
# expressed as percentage of EU average
# EUR_HAB_EU_2010
# TechEmp_2012 percentage of employees working in the “high-tech industry”
# (NACE r.2 code HTC) in a given region and t = 2012
# NUTS_ID NUTS2 region-identifier (NUTS.2010)
# long, lat coordinates of regions' centroids
#
#
# Unemployment model to be estimated:
#
# U_pc_2012 <- I(EUR_HAB_EU_2011-EUR_HAB_EU_2010) + TechEmp_2012
#
#
# Distance based neighbors - maximum neighbor distance threshold: 250 km
#
#
#
# Step 1 Prepare spatial objects for subsequent analysis:
#
# (a) coordinates and IDs
coords <- CE_data[,c("long", "lat")]
coords <- coordinates(coords)
IDs <- CE_data$NUTS_ID
# (b) identify neighbors given tau distance threshold
nb250km <- dnearneigh(coords, d1=0, d2=250, longlat=T, row.names = IDs)
summary(nb250km)
# (c) calculate the spatial weights matrix
W.matrix <- nb2listw(nb250km)
summary(W.matrix)
#
#
#
# Step 2 Spatial lag model estimation, impacts
#
spatial.lag <- lagsarlm(U_pc_2012 ~ I(EUR_HAB_EU_2011-EUR_HAB_EU_2010) + TechEmp_2012,
data=CE_data, W.matrix)
summary(spatial.lag)
# Impacts
?spatialreg::impacts
impacts(spatial.lag, listw= W.matrix)
#
impacts.obj <- impacts(spatial.lag, listw= W.matrix, R=500)
summary(impacts.obj, zstats=T, short=T)
#
plot(impacts.obj)
#
#
#
# Step 3 Spatial Durbin model estimation: coefficients & impacts
#
spatial.Durbin <- lagsarlm(U_pc_2012 ~ I(EUR_HAB_EU_2011-EUR_HAB_EU_2010) + TechEmp_2012,
data=CE_data, W.matrix, Durbin = T)
#
summary(spatial.Durbin) # Note the sign on spatial lag of TechEmp
#
# Impacts
impacts(spatial.Durbin, listw= W.matrix)
#
impacts.obj2 <- impacts(spatial.Durbin, listw= W.matrix, R=500)
summary(impacts.obj2, zstats=T, short=T)
plot(impacts.obj2)
#
#
#
#
#
## Quick Exercise:
## Evaluate stability of the results with respect to
## changing spatial structure
## use kNN method to set-up neighbors, as follows:
?knearneigh # use k = 4
?knn2nb # use symmetric transformation: sym = T
W.matrix <- nb2listw() # use nb2listw with the output from knn2bn
##
#
#
#
#