getspanel package can be downloaded and installed
from CRAN here by simply
The source code of the package is on GitHub and the development version can be installed using:
# install.packages("devtools") devtools::install_github("moritzpschwarz/getspanel", ref = "devel")
Once installed we need to load the library:
Currently the package is called getspanel to align with the gets package, but it’s main function of course remains the isatpanel function.
The isatpanel function implements the empirical break detection algorithm that is described in a paper by Felix Pretis and Moritz Schwarz and was applied to a study by Nico Koch and colleagues on EU Road CO2 emissions, which was published in Nature Energy in 2022.
A quick overview over what has changed:
We can now use the function approach as well as the traditional
gets approach. This means that we can specify a model using
mxreg as well as
id as vectors, but we can now also simply supply a
data.frame and a
function in the form
y ~ x + z + I(x^2) to e.g. specify polynomials. This means
we will then need an
index argument, which specifies
ar argument now works
We can now use the
fixest package to speed up model
estimation with large
i (for short panels, the default
method is still faster).The package can be activated using the new
fixest package also allows us to calculate
clustered standard errors.
We can now be certain that unbalanced panels would work as intended, which was not the case before.
have been removed. Instead the function now produces the break matrix
itself. This now implements the following saturation methods in a user
iis: Impulse Indicator Saturation
jsis: Joint Step Indicator Saturation (Common Breaks over time)
csis: Coefficient Step Indicator Saturation (Common Coefficient Breaks over time)
fesis: Fixed Effect Step Indicator Saturation (Breaks in the Group Fixed Effect over time)
cfesis: Coefficient Fixed Effect Step Indicator Saturation (Breaks in the coefficient for each individual)
We first load some data of EU CO2 Emissions in the housing sector.
data("EUCO2residential") head(EUCO2residential) # A tibble: 6 × 9 country year lgdp lhdd lcdd urban av.rate pop agg.directem<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 Austria 1969 25.6 NA NA 65.2 NA NA NA 2 Austria 1970 25.7 NA NA 65.3 NA NA NA 3 Austria 1971 25.8 NA NA 65.3 NA 7500482 NA 4 Austria 1972 25.8 NA NA 65.3 NA 7544201 NA 5 Austria 1973 25.9 NA NA 65.3 NA 7586115 NA 6 Austria 1974 25.9 NA NA 65.3 NA 7599038 NA # let's subset this a little bit to speed this up <- EUCO2residential[EUCO2residential$year > 2000 & EUCO2residential $country %in% c("Germany", "Austria", EUCO2residential"Belgium", "Italy", "Sweden", "Denmark"),] # let's create a log emissions per capita variable $lagg.directem_pc <- log(EUCO2residential$agg.directem/EUCO2residential$pop) EUCO2residential # and let's also turn off printing the intermediate output from isatpanel options(print.searchoutput = FALSE)
Let’s look at how we input what we want to model. Each
isatpanel command takes:
In the gets package style i.e. using vectors and
matrices to specify
But also in a form that resembles the
plm specification i.e. inputting a
argument as well as character vectors for
index (in the
This already means that the following two commands will give the same result:
Using the new method
<- isatpanel(data = EUCO2residential, is_lm formula = lagg.directem_pc ~ lgdp + I(lgdp^2) + pop, index = c("country","year"), effect = "twoways", fesis = TRUE)
Using the traditional method
<- isatpanel(y = EUCO2residential$lagg.directem_pc, is_gets mxreg = EUCO2residential$lgdp, time = EUCO2residential$year, id = EUCO2residential$country, effect = "twoways", fesis = TRUE)
From here onwards, I will use the
We can plot these simply using the default plotting methods (rely on the ggplot2 package):
This argument works just as in the gets package. The
method simply adds a
1 dummy for each
iis = TRUE.
<- isatpanel(data = EUCO2residential, iis_example formula = lagg.directem_pc ~ lgdp + I(lgdp^2) + pop, index = c("country","year"), effect = "twoways", iis = TRUE, fesis = TRUE)
Traditional Step Indicator Saturation does not make sense in a panel
setting. Therefore, the gets function of
sis is disabled.
It is possible, however, to consider Step Indicator Saturation with
common breaks across individuals. Such indicators would be collinear, if
effects = c("twoways") or
effects = c("time")
i.e. if Time Fixed Effects are included.
effect = "individual" then we can use
jsis = TRUE to select over all individual time fixed
<- isatpanel(data = EUCO2residential, jsis_example formula = lagg.directem_pc ~ lgdp + I(lgdp^2) + pop, index = c("country","year"), effect = "individual", jsis = TRUE)
Note: This method has only been tested using the
lm implementation (using
This method allows detection of coefficient breaks that are common
across all groups. It is the interaction between
the relevant coefficient.
To illustrate this, as well as the advantages of using the
lm approach, we include a non-linear term of the lgdp
<- isatpanel(data = EUCO2residential, csis_example formula = lagg.directem_pc ~ lgdp + I(lgdp^2) + pop, index = c("country","year"), effect = "twoways", csis = TRUE)