├── LICENSE.md ├── Python ├── scpi_germany.csv ├── scpi_illustration-multi.py ├── scpi_illustration.py ├── scpi_illustration_plot-multi.py ├── scpi_illustration_plot.py └── scpi_pkg │ ├── LICENSE │ ├── README.md │ ├── docs │ ├── Legal.rst │ ├── Makefile │ ├── _build │ │ ├── doctrees │ │ │ ├── Legal.doctree │ │ │ ├── environment.pickle │ │ │ ├── index.doctree │ │ │ ├── scdata.doctree │ │ │ ├── scdataMulti.doctree │ │ │ ├── scest.doctree │ │ │ ├── scpi.doctree │ │ │ ├── scplot.doctree │ │ │ └── scplotMulti.doctree │ │ └── html │ │ │ ├── .buildinfo │ │ │ ├── Legal.html │ │ │ ├── _modules │ │ │ ├── index.html │ │ │ └── scpi_pkg │ │ │ │ ├── scdata.html │ │ │ │ ├── scdataMulti.html │ │ │ │ ├── scest.html │ │ │ │ ├── scpi.html │ │ │ │ ├── scplot.html │ │ │ │ └── scplotMulti.html │ │ │ ├── _sources │ │ │ ├── Legal.rst.txt │ │ │ ├── index.rst.txt │ │ │ ├── scdata.rst.txt │ │ │ ├── scdataMulti.rst.txt │ │ │ ├── scest.rst.txt │ │ │ ├── scpi.rst.txt │ │ │ ├── scplot.rst.txt │ │ │ └── scplotMulti.rst.txt │ │ │ ├── _static │ │ │ ├── _sphinx_javascript_frameworks_compat.js │ │ │ ├── basic.css │ │ │ ├── css │ │ │ │ ├── badge_only.css │ │ │ │ ├── fonts │ │ │ │ │ ├── Roboto-Slab-Bold.woff │ │ │ │ │ ├── Roboto-Slab-Bold.woff2 │ │ │ │ │ ├── Roboto-Slab-Regular.woff │ │ │ │ │ ├── Roboto-Slab-Regular.woff2 │ │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ │ ├── fontawesome-webfont.svg │ │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ │ ├── fontawesome-webfont.woff │ │ │ │ │ ├── fontawesome-webfont.woff2 │ │ │ │ │ ├── lato-bold-italic.woff │ │ │ │ │ ├── lato-bold-italic.woff2 │ │ │ │ │ ├── lato-bold.woff │ │ │ │ │ ├── lato-bold.woff2 │ │ │ │ │ ├── lato-normal-italic.woff │ │ │ │ │ ├── lato-normal-italic.woff2 │ │ │ │ │ ├── lato-normal.woff │ │ │ │ │ └── lato-normal.woff2 │ │ │ │ └── theme.css │ │ │ ├── doctools.js │ │ │ ├── documentation_options.js │ │ │ ├── file.png │ │ │ ├── jquery-3.6.0.js │ │ │ ├── jquery.js │ │ │ ├── js │ │ │ │ ├── badge_only.js │ │ │ │ ├── html5shiv-printshiv.min.js │ │ │ │ ├── html5shiv.min.js │ │ │ │ └── theme.js │ │ │ ├── language_data.js │ │ │ ├── minus.png │ │ │ ├── plus.png │ │ │ ├── pygments.css │ │ │ ├── searchtools.js │ │ │ ├── sphinx_highlight.js │ │ │ ├── underscore-1.13.1.js │ │ │ └── underscore.js │ │ │ ├── genindex.html │ │ │ ├── index.html │ │ │ ├── objects.inv │ │ │ ├── scdata.html │ │ │ ├── scdataMulti.html │ │ │ ├── scest.html │ │ │ ├── scpi.html │ │ │ ├── scplot.html │ │ │ ├── scplotMulti.html │ │ │ ├── search.html │ │ │ └── searchindex.js │ ├── conf.py │ ├── index.rst │ ├── make.bat │ ├── scdata.rst │ ├── scdataMulti.rst │ ├── scest.rst │ ├── scpi.rst │ ├── scplot.rst │ └── scplotMulti.rst │ ├── pyproject.toml │ ├── setup.cfg │ └── src │ ├── scpi_pkg.egg-info │ ├── PKG-INFO │ ├── SOURCES.txt │ ├── dependency_links.txt │ ├── requires.txt │ └── top_level.txt │ └── scpi_pkg │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── funs.cpython-38.pyc │ ├── funs.cpython-39.pyc │ ├── scdata.cpython-310.pyc │ ├── scdata.cpython-38.pyc │ ├── scdata.cpython-39.pyc │ ├── scdataMulti.cpython-310.pyc │ ├── scdataMulti.cpython-38.pyc │ ├── scdataMulti.cpython-39.pyc │ ├── scest.cpython-310.pyc │ ├── scest.cpython-38.pyc │ ├── scest.cpython-39.pyc │ ├── scpi.cpython-310.pyc │ ├── scpi.cpython-38.pyc │ ├── scpi.cpython-39.pyc │ ├── scplot.cpython-310.pyc │ ├── scplot.cpython-38.pyc │ ├── scplot.cpython-39.pyc │ ├── scplotMulti.cpython-310.pyc │ ├── scplotMulti.cpython-38.pyc │ ├── scplotMulti.cpython-39.pyc │ └── support.cpython-38.pyc │ ├── funs.py │ ├── scdata.py │ ├── scdataMulti.py │ ├── scest.py │ ├── scpi.py │ ├── scplot.py │ ├── scplotMulti.py │ └── version.py ├── R ├── scpi.pdf ├── scpi │ ├── .github │ │ ├── .gitignore │ │ └── workflows │ │ │ └── R-CMD-check.yaml │ ├── DESCRIPTION │ ├── NAMESPACE │ ├── R │ │ ├── .Rhistory │ │ ├── data.R │ │ ├── scdata.R │ │ ├── scdataMulti.R │ │ ├── scdataMulti_methods.R │ │ ├── scdata_methods.R │ │ ├── scest.R │ │ ├── scest_methods.R │ │ ├── scpi-package.R │ │ ├── scpi.R │ │ ├── scpi_methods.R │ │ ├── scplot.R │ │ ├── scplotMulti.R │ │ └── supporting_functions.R │ ├── data │ │ └── scpi_germany.RData │ ├── man │ │ ├── coef.scest.Rd │ │ ├── coef.scpi.Rd │ │ ├── print.scdata.Rd │ │ ├── print.scdataMulti.Rd │ │ ├── print.scest.Rd │ │ ├── print.scpi.Rd │ │ ├── scdata.Rd │ │ ├── scdataMulti.Rd │ │ ├── scest.Rd │ │ ├── scpi-package.Rd │ │ ├── scpi.Rd │ │ ├── scpi_germany.Rd │ │ ├── scplot.Rd │ │ ├── scplotMulti.Rd │ │ ├── summary.scdata.Rd │ │ ├── summary.scdataMulti.Rd │ │ ├── summary.scest.Rd │ │ └── summary.scpi.Rd │ └── tests │ │ ├── testthat.R │ │ └── testthat │ │ ├── test-scdata.R │ │ ├── test-scdataMulti.R │ │ ├── test-scest.R │ │ └── test-scpi.R ├── scpi_3.0.0.tar.gz ├── scpi_germany.csv ├── scpi_illustration-multi.R ├── scpi_illustration.R ├── scpi_illustration_plot-multi.R └── scpi_illustration_plot.R ├── README.md ├── python └── scpi_pkg │ ├── dist │ ├── scpi_pkg-3.0.0-py3-none-any.whl │ └── scpi_pkg-3.0.0.tar.gz │ └── src │ └── scpi_pkg │ └── __pycache__ │ ├── funs.cpython-312.pyc │ ├── scdata.cpython-312.pyc │ ├── scdataMulti.cpython-312.pyc │ ├── scest.cpython-312.pyc │ ├── scpi.cpython-312.pyc │ ├── scplot.cpython-312.pyc │ └── scplotMulti.cpython-312.pyc └── stata ├── scdata.ado ├── scdata.pdf ├── scdata.sthlp ├── scdatamulti.ado ├── scdatamulti.pdf ├── scdatamulti.sthlp ├── scest.ado ├── scest.pdf ├── scest.sthlp ├── scpi.ado ├── scpi.pdf ├── scpi.pkg ├── scpi.sthlp ├── scpi_germany.dta ├── scpi_illustration-multi.do ├── scpi_illustration.do ├── scpi_illustration_plot-multi.do ├── scpi_illustration_plot.do ├── scplot.ado ├── scplot.pdf ├── scplot.sthlp ├── scplotmulti.ado ├── scplotmulti.pdf ├── scplotmulti.sthlp └── stata.toc /LICENSE.md: -------------------------------------------------------------------------------- 1 | GPL-3.0 2 | -------------------------------------------------------------------------------- /Python/scpi_illustration-multi.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # SCPI Python Package 3 | # Script for Empirical Illustration - Multiple Treated Units 4 | # Authors: Matias D. Cattaneo, Yingjie Feng, Filippo Palomba and Rocio Titiunik 5 | ############################################################################### 6 | 7 | ######################################## 8 | # Load SCPI_PKG package 9 | import pandas 10 | import numpy 11 | import os 12 | from warnings import filterwarnings 13 | from scpi_pkg.scdataMulti import scdataMulti 14 | from scpi_pkg.scest import scest 15 | from scpi_pkg.scpi import scpi 16 | from scpi_pkg.scplotMulti import scplotMulti 17 | 18 | ######################################## 19 | # Load database 20 | os.chdir("YOUR_PATH_HERE") 21 | data = pandas.read_csv("scpi_germany.csv") 22 | 23 | filterwarnings("ignore") 24 | numpy.random.seed(8894) 25 | 26 | ############################################################################## 27 | # MULTIPLE TREATED UNITS 28 | ############################################################################## 29 | 30 | # create treatment dummy 31 | data['status'] = 0 32 | data.loc[(data['country'] == "West Germany") & (data['year'] >= 1991), 'status'] = 1 33 | 34 | # Create a second placebo treated unit 35 | data.loc[(data['country'] == "Italy") & (data['year'] >= 1992), 'status'] = 1 36 | 37 | id_var = 'country' 38 | time_var = 'year' 39 | treatment_var = 'status' 40 | outcome_var = 'gdp' 41 | covs_adj = {'Italy': ['constant', 'trend'], 42 | 'West Germany': [['constant', 'trend'], ['constant', 'trend']]} 43 | 44 | 45 | ############################################### 46 | # unit-time treatment effect 47 | ############################################### 48 | 49 | aux = scdataMulti(df=data, 50 | id_var=id_var, 51 | treatment_var=treatment_var, 52 | outcome_var=outcome_var, 53 | time_var=time_var, 54 | features={"Italy": ["gdp", "trade"], 55 | "West Germany": ["gdp", "infrate"]}, 56 | constant={'Italy': True, 'West Germany': False}, 57 | cointegrated_data=True, cov_adj=covs_adj) 58 | 59 | res = scest(aux, w_constr={'name': 'simplex'}) 60 | scplotMulti(res) 61 | 62 | res_pi = scpi(aux, w_constr={'name': 'simplex'}, sims=50, cores=1) 63 | 64 | # plot series 65 | scplotMulti(res_pi, ptype="series") 66 | 67 | # plot treatment effects 68 | scplotMulti(res_pi, ptype="treatment", joint=True) 69 | 70 | ############################################### 71 | # average unit post-treatment effect 72 | ############################################### 73 | 74 | aux = scdataMulti(df=data, 75 | id_var=id_var, 76 | treatment_var=treatment_var, 77 | outcome_var=outcome_var, 78 | time_var=time_var, 79 | features={"Italy": ["gdp", "trade"], 80 | "West Germany": ["gdp", "infrate"]}, 81 | constant={'Italy': True, 'West Germany': False}, 82 | cointegrated_data=True, 83 | cov_adj=covs_adj, effect="unit") 84 | 85 | res = scest(aux, w_constr={'name': 'simplex'}) 86 | scplotMulti(res) 87 | 88 | res_pi = scpi(aux, w_constr={'name': 'simplex'}, sims=50, cores=1) 89 | 90 | # plot series 91 | scplotMulti(res_pi, ptype="series") 92 | 93 | # plot treatment effects 94 | scplotMulti(res_pi, ptype="treatment", joint=True) 95 | 96 | ############################################### 97 | # average post-treatment effect on the treated 98 | ############################################### 99 | 100 | aux = scdataMulti(df=data, 101 | id_var=id_var, 102 | treatment_var=treatment_var, 103 | outcome_var=outcome_var, 104 | time_var=time_var, 105 | features={"Italy": ["gdp", "trade"], 106 | "West Germany": ["gdp", "infrate"]}, 107 | constant={'Italy': True, 'West Germany': False}, 108 | cointegrated_data=True, 109 | cov_adj=covs_adj, effect="time") 110 | 111 | res = scest(aux, w_constr={'name': 'simplex'}) 112 | scplotMulti(res) 113 | 114 | res_pi = scpi(aux, w_constr={'name': 'simplex'}, sims=50, cores=1) 115 | 116 | # plot series 117 | scplotMulti(res_pi, ptype="series") 118 | 119 | # plot treatment effects 120 | scplotMulti(res_pi, ptype="treatment", joint=True) 121 | -------------------------------------------------------------------------------- /Python/scpi_illustration_plot-multi.py: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # SCPI Python Package 3 | # Script for Visualization - Multiple Treated Units 4 | # Authors: Matias D. Cattaneo, Yingjie Feng, Filippo Palomba and Rocio Titiunik 5 | ################################################################################ 6 | 7 | ######################################## 8 | # Load SCPI_PKG package 9 | import pandas 10 | import numpy 11 | import os 12 | from copy import deepcopy 13 | from plotnine import ggplot, aes, geom_point, geom_errorbar, geom_vline, geom_line, theme, theme_bw 14 | from plotnine import element_blank, labs, guide_legend, scale_color_manual, ggtitle, facet_wrap, geom_ribbon 15 | from warnings import filterwarnings 16 | from scpi_pkg.scdata import scdata 17 | from scpi_pkg.scdataMulti import scdataMulti 18 | from scpi_pkg.scest import scest 19 | from scpi_pkg.scpi import scpi 20 | from scpi_pkg.scplot import scplot 21 | from scpi_pkg.scplotMulti import scplotMulti 22 | 23 | 24 | ######################################## 25 | # Load database 26 | os.chdir("YOUR_PATH_HERE") 27 | data = pandas.read_csv("scpi_germany.csv") 28 | 29 | numpy.random.seed(8894) 30 | ############################################################################## 31 | # MULTIPLE TREATED UNITS 32 | ############################################################################## 33 | 34 | ######################################## 35 | # Load database 36 | data = pandas.read_csv("scpi_germany.csv") 37 | 38 | # create treatment dummy 39 | data['status'] = 0 40 | data.loc[(data['country'] == "West Germany") & (data['year'] >= 1991), 'status'] = 1 41 | 42 | # fictitious second treated unit for the sake of the example 43 | data.loc[(data['country'] == "Italy") & (data['year'] >= 1992), 'status'] = 1 44 | 45 | id_var = 'country' 46 | time_var = 'year' 47 | treatment_var = 'status' 48 | outcome_var = 'gdp' 49 | covs_adj = {'Italy': ['constant', 'trend'], 50 | 'West Germany': [['constant', 'trend'], ['constant', 'trend']]} 51 | 52 | aux = scdataMulti(df=data, 53 | id_var=id_var, 54 | treatment_var=treatment_var, 55 | outcome_var=outcome_var, 56 | time_var=time_var, 57 | features={"Italy": ["gdp", "trade"], 58 | "West Germany": ["gdp", "infrate"]}, 59 | constant={'Italy': True, 'West Germany': False}, 60 | cointegrated_data=True, 61 | cov_adj=covs_adj) 62 | 63 | result = scpi(aux, w_constr={'name': 'simplex'}, sims=10, cores=1) 64 | 65 | plot = scplotMulti(result, ptype="series", joint=True, save_data='__scpi_plot') 66 | 67 | toplot = pandas.read_csv('__scpi_plot.csv') 68 | 69 | Y_actual = deepcopy(result.Y_df) 70 | Y_actual.columns = ['ID', 'Time', 'Treatment', 'Actual'] 71 | Y_actual.set_index(['ID', 'Time'], drop=True, inplace=True) 72 | treated_periods = Y_actual.loc[Y_actual['Treatment'] == 1] 73 | treated_periods.reset_index(drop=False, inplace=True) 74 | treated_reception = treated_periods.groupby('ID').min() 75 | treated_reception.columns = ["Tdate", "Treatment", "Actual"] 76 | treated_reception['Tdate'] = treated_reception['Tdate'] - 1 / 2 77 | treated_reception.reset_index(drop=False, inplace=True) 78 | 79 | plot_struc = (ggplot(data=toplot) + theme_bw() + 80 | theme(panel_grid=element_blank(), 81 | legend_position=(.5, .05), 82 | legend_direction='horizontal', 83 | legend_box='horizontal', 84 | legend_title=element_blank(), 85 | subplots_adjust={'bottom': 0.2}) + 86 | labs(x="Date", y="Outcome")) 87 | 88 | plot = (plot_struc + 89 | geom_line(mapping=aes(x='Time', y='Outcome', colour='Type')) + 90 | geom_point(mapping=aes(x='Time', y='Outcome', colour='Type'), size=1.5) + 91 | geom_vline(data=treated_reception, mapping=aes(xintercept='Tdate', group='ID')) + 92 | facet_wrap('ID', ncol=2) + 93 | scale_color_manual(name="", values=["black", "blue"], 94 | labels=["Treated", "Synthetic Control"])) 95 | 96 | # add prediction intervals 97 | plot_w1 = (plot + 98 | geom_errorbar(data=toplot, 99 | mapping=aes(x='Time', ymin='Lower_gaussian', ymax='Upper_gaussian'), 100 | colour='blue', width=0.5, linetype="solid") + 101 | ggtitle("In and Out of Sample Uncertianty - Subgaussian Bounds")) 102 | 103 | # add shaded area 104 | plotdf = toplot[toplot['Type'] == 'Synthetic'] 105 | plot_w1 = (plot_w1 + 106 | geom_ribbon(data=plotdf, 107 | mapping=aes(x='Time', ymin='Lower_joint', ymax='Upper_joint'), 108 | fill='blue', alpha=0.1)) 109 | -------------------------------------------------------------------------------- /Python/scpi_pkg/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 The Python Packaging Authority 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /Python/scpi_pkg/README.md: -------------------------------------------------------------------------------- 1 | # SCPI_PKG 2 | 3 | The `scpi_pkg` package provides Python implementations of estimation and inference procedures for Synthetic Control methods. 4 | 5 | ## Authors 6 | 7 | Matias D. Cattaneo () 8 | 9 | Yingjie Feng () 10 | 11 | Filippo Palomba () 12 | 13 | Rocio Titiunik () 14 | 15 | ## Website 16 | 17 | https://nppackages.github.io/scpi/ 18 | 19 | ## Installation 20 | 21 | To install/update use pip 22 | 23 | ``` 24 | pip install scpi_pkg 25 | ``` 26 | 27 | # Usage 28 | 29 | ``` 30 | from from scpi_pkg.scdata import scdata 31 | from from scpi_pkg.scdataMulti import scdataMulti 32 | from scpi_pkg.scest import scest 33 | from scpi_pkg.scpi import scpi 34 | from scpi_pkg.scplot import scplot 35 | from scpi_pkg.scplotMulti import scplotMulti 36 | ``` 37 | 38 | - Replication: [Germany reunification example](https://github.com/nppackages/scpi/blob/main/Python/scpi_illustration.py). 39 | 40 | ## Dependencies 41 | 42 | - cvxpy (>= 1.1.18) 43 | - dask (>= 2021.04.0) 44 | - ecos (>= 2.0.7) 45 | - luddite (>= 1.0.2) 46 | - numpy (>= 1.20.1) 47 | - pandas (>= 1.5.0) 48 | - plotnine (>= 0.8.0) 49 | - scikit-learn (>= 0.24.1) 50 | - scipy (>= 1.7.1) 51 | - statsmodels (>= 0.12.2) 52 | 53 | ## References 54 | 55 | For overviews and introductions, see [nppackages website](https://nppackages.github.io/). 56 | 57 | ### Software and Implementation 58 | 59 | - Cattaneo, Feng, Palomba, and Titiunik (2024+) [scpi: Uncertainty Quantification for Synthetic Control Estimators](https://arxiv.org/abs/2202.05984). forthcoming at *Journal of Statistical Software.* 60 | 61 | ### Technical and Methodological 62 | 63 | - Cattaneo, Feng, and Titiunik (2021): [Prediction Intervals for Synthetic Control Methods](https://cattaneo.princeton.edu/papers/Cattaneo-Feng-Titiunik_2021_JASA.pdf). 64 | _Journal of the American Statistical Association_. 65 | - Cattaneo, Feng, Palomba, and Titiunik (2023): [Uncertainty Quantification in Synthetic Controls with Staggered Treatment Adoption](https://arxiv.org/abs/2210.05026), working paper. 66 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/Legal.rst: -------------------------------------------------------------------------------- 1 | ################### 2 | License and funding 3 | ################### 4 | 5 | This work was supported by the National Science Foundation through grants 6 | `SES-1947805 `_ and 7 | `SES-2019432 `_, 8 | and by the National Institutes of Health through grant 9 | `R01 GM072611-16 `_. -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/doctrees/Legal.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/doctrees/Legal.doctree -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/doctrees/environment.pickle -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/doctrees/index.doctree -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/doctrees/scdata.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/doctrees/scdata.doctree -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/doctrees/scdataMulti.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/doctrees/scdataMulti.doctree -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/doctrees/scest.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/doctrees/scest.doctree -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/doctrees/scpi.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/doctrees/scpi.doctree -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/doctrees/scplot.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/doctrees/scplot.doctree -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/doctrees/scplotMulti.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/doctrees/scplotMulti.doctree -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: f870938cea0e6f2cf85b7316aea434ee 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_modules/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Overview: module code — scpi-pkg 2.2.2 documentation 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 57 | 58 |
62 | 63 |
64 |
65 |
66 |
    67 |
  • 68 | 69 |
  • 70 |
  • 71 |
72 |
73 |
74 |
75 |
76 | 77 |

All modules for which code is available

78 | 85 | 86 |
87 |
88 |
89 | 90 |
91 | 92 |
93 |

© Copyright 2022, Matias Cattaneo, Yingjie Feng, Filippo Palomba, Rocio Titiunik.

94 |
95 | 96 | Built with Sphinx using a 97 | theme 98 | provided by Read the Docs. 99 | 100 | 101 |
102 |
103 |
104 |
105 |
106 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_sources/Legal.rst.txt: -------------------------------------------------------------------------------- 1 | ################### 2 | License and funding 3 | ################### 4 | 5 | This work was supported by the National Science Foundation through grants 6 | `SES-1947805 `_ and 7 | `SES-2019432 `_, 8 | and by the National Institutes of Health through grant 9 | `R01 GM072611-16 `_. -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | .. scpi-pkg documentation master file, created by 2 | sphinx-quickstart on Tue Feb 22 10:21:54 2022. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to scpi-pkg's documentation! 7 | ==================================== 8 | The scpi package provides Python, R, and Stata implementations of estimation and inference procedures 9 | for synthetic control methods with multiple treated units and staggered adoption using least squares, 10 | lasso, ridge, or simplex-type constraints. Uncertainty is quantifed using 11 | prediction intervals as developed in `Cattaneo, Feng, and Titiunik (2021) `_ 12 | for a single treated unit and in `Cattaneo, Feng, Palomba, and Titiunik (2022b) `_ for 13 | multiple treated units and staggered adoption. 14 | 15 | Companion `R `_ and `Stata `_ packages are described in 16 | `Cattaneo, Feng, Palomba, and Titiunik (2022a) `_. 17 | 18 | Related Stata, R, and Python packages useful for inference in synthetic control methods are described 19 | in the following website: 20 | 21 | `https://nppackages.github.io/scpi/ `_ 22 | 23 | For an introduction to synthetic control methods, see `Abadie (2021) `_ and 24 | references therein. 25 | 26 | 27 | .. toctree:: 28 | :maxdepth: 2 29 | :caption: Contents: 30 | 31 | scdata 32 | scdataMulti 33 | scest 34 | scpi 35 | scplot 36 | scplotMulti 37 | Legal 38 | 39 | 40 | Indices and tables 41 | ================== 42 | 43 | * :ref:`genindex` 44 | * :ref:`modindex` 45 | * :ref:`search` 46 | 47 | 48 | References 49 | ========== 50 | Abadie, A. (2021), “Using Synthetic Controls: Feasibility, Data Requirements, and Methodological 51 | Aspects,” Journal of Economic Literature, 59, 391-425. 52 | 53 | Cattaneo, M. D., Feng, Y., and Titiunik, R. (2021), “Prediction Intervals for Synthetic Control 54 | Methods,” Journal of the American Statistical Association, 116, 1865-1880. 55 | 56 | Cattaneo, M. D., Palomba, F., Feng, Y., and Titiunik, R. (2022a), “scpi: Uncertainty Quantification for 57 | Synthetic Control Estimators”. 58 | 59 | Cattaneo, M. D., Palomba, F., Feng, Y., and Titiunik, R. (2022b), “Uncertainty Quantification in Synthetic 60 | Controls with Staggered Treatment Adoption”. -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_sources/scdata.rst.txt: -------------------------------------------------------------------------------- 1 | Data Preparation for Synthetic Control (:py:mod:`scdata.scdata`) 2 | ======================================================================== 3 | 4 | This page describes the function ``scdata`` to prepare data for synthetic control designs. The function 5 | produces an object of class ``scdata_output`` to be passed to ``scest`` or ``scpi``. 6 | 7 | The command prepares the data to be used by scest or scpi for point estimation and inference procedures using 8 | Synthetic Control. It allows the user to specify the outcome variable, the features of the treated unit 9 | to be matched, and covariate-adjustment feature by feature. The names of the output matrices 10 | follow the notation proposed in `Cattaneo, Feng, and Titiunik (2021) `_. 11 | 12 | Syntax 13 | --------- 14 | 15 | .. currentmodule:: scpi_pkg.scdata 16 | .. autofunction:: scdata 17 | 18 | 19 | Dependencies 20 | ------------ 21 | 22 | **Python**: `cvxpy `_, 23 | 24 | `dask `_, 25 | 26 | `numpy `_, 27 | 28 | `pandas `_, 29 | 30 | `plotnine `_, 31 | 32 | `scikit-learn `_, 33 | 34 | `scipy `_, 35 | 36 | `statsmodels `_ 37 | 38 | **scpi_pkg**: none 39 | 40 | Usage 41 | ----- 42 | 43 | This example shows how to prepare the data for synthetic control methods. The raw data can be downloaded 44 | `here `_:: 45 | 46 | import pandas 47 | from scpi_pkg.scdata import scdata 48 | 49 | data = pandas.read_csv("scpi_germany.csv") 50 | 51 | id_var = 'country' 52 | outcome_var = 'gdp' 53 | time_var = 'year' 54 | features = None 55 | cov_adj = None 56 | period_pre = numpy.arange(1960, 1991) 57 | period_post = numpy.arange(1991, 2004) 58 | unit_tr = 'West Germany' 59 | unit_co = list(set(data[id_var].to_list())) 60 | unit_co = [cou for cou in unit_co if cou != 'West Germany'] 61 | constant = True 62 | report_missing = False 63 | cointegrated_data = True 64 | 65 | data_prep = scdata(df=data, id_var=id_var, time_var=time_var, 66 | outcome_var=outcome_var, period_pre=period_pre, 67 | period_post=period_post, unit_tr=unit_tr, 68 | unit_co=unit_co, features=features, cov_adj=cov_adj, 69 | cointegrated_data=cointegrated_data, constant=constant, 70 | report_missing=report_missing) 71 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_sources/scdataMulti.rst.txt: -------------------------------------------------------------------------------- 1 | Data Preparation for Synthetic Control with Staggered Adoption (:py:mod:`scdataMulti.scdataMulti`) 2 | ==================================================================================================== 3 | 4 | This page describes the function ``scdataMulti`` to prepare data for synthetic control designs in the general 5 | case of multiple treated units, possibly with staggered adoption. The function 6 | produces an object of class ``scdataMulti_output`` to be passed to ``scest`` or ``scpi``. 7 | 8 | The command prepares the data to be used by scest or scpi for point estimation and inference procedures using 9 | Synthetic Control. It allows the user to specify the outcome variable and, for each treated unit, the features 10 | to be matched, and covariate-adjustment feature by feature. The names of the output matrices 11 | follow the notation proposed in `Cattaneo, Feng, Palomba, and Titiunik (2022) `_. 12 | 13 | Syntax 14 | --------- 15 | 16 | .. currentmodule:: scpi_pkg.scdataMulti 17 | .. autofunction:: scdataMulti 18 | 19 | 20 | Dependencies 21 | ------------ 22 | 23 | **Python**: `cvxpy `_, 24 | 25 | `dask `_, 26 | 27 | `ecos `_, 28 | 29 | `numpy `_, 30 | 31 | `pandas `_, 32 | 33 | `plotnine `_, 34 | 35 | `scikit-learn `_, 36 | 37 | `scipy `_, 38 | 39 | `statsmodels `_ 40 | 41 | **scpi_pkg**: scdata 42 | 43 | Usage 44 | ----- 45 | Some examples regarding features and cov_adj:: 46 | 47 | # same features for all treated units 48 | features = {'anyname': [list of variables to match on]} 49 | 50 | # specify features for each treated unit 51 | features = {'treated_1': [list of variables to match on], 52 | 'treated_2': [(possibly different) list of variables to match on]} 53 | 54 | # same covariate adjustment for all treated units for all features 55 | cov_adj = {'anyname': ['constant', 'trend']} 56 | 57 | # same covariate adjustment for all treated units but feature-specific (say, three features) 58 | cov_adj = {'anyname': [['constant', 'trend'], [], ['constant']]} 59 | 60 | # different covariate adjustment for each treated unit and feature-specific (say, two features for the first unit 61 | # and three for the second treated unit) 62 | cov_adj = {'treated_1': [['constant'], [] ], 63 | 'treated_2': [['constant', 'trend'], ['trend'], []]} 64 | 65 | # unit specific presence of global constant 66 | constant = {'treated_1': True, 'treated_2': False} 67 | 68 | # unit specific presence of cointegration 69 | cointegrated_data = {'treated_1': True, 'treated_2': False} 70 | 71 | # unit specific presence of anticipation effects 72 | anticipation = {'treated_1': 0, 'treated_2': 1} 73 | 74 | aux = scdataMulti(df=df, 75 | id_var='country', 76 | treatment_var='treatment', 77 | outcome_var='gdp', 78 | time_var='year', 79 | features=features, 80 | constant=constant, 81 | anticipation=anticipation, 82 | cointegrated_data=cointegrated_data) 83 | 84 | This example shows how to prepare the data for synthetic control methods. The raw data can be downloaded 85 | `here `_:: 86 | 87 | import pandas 88 | from scdataMulti import scdataMulti 89 | 90 | df = pandas.read_csv("scpi_germany.csv") 91 | 92 | # Create a second placebo treated unit 93 | df.loc[(df['country'] == "Italy") & (df['year'] >= 1992), 'status'] = 1 94 | 95 | aux = scdataMulti(df=df, 96 | id_var='country', 97 | treatment_var='treatment', 98 | outcome_var='gdp', 99 | time_var='year') -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_sources/scest.rst.txt: -------------------------------------------------------------------------------- 1 | Point estimation for Synthetic Control (:py:mod:`scest.scest`) 2 | ======================================================================== 3 | 4 | This page describes the function ``scest`` to implement point estimation for synthetic control methods 5 | using least squares, lasso, ridge, or simplex-type constraints. 6 | For further information see `Cattaneo, Feng, and Titiunik (2021) `_. 7 | The names of the output matrices follow the notation proposed in `Cattaneo, Feng, Palomba, and Titiunik (2022) `_ 8 | 9 | Syntax 10 | --------- 11 | 12 | .. currentmodule:: scpi_pkg.scest 13 | .. autofunction:: scest 14 | 15 | 16 | Dependencies 17 | ------------ 18 | 19 | **Python**: `cvxpy `_, 20 | 21 | `dask `_, 22 | 23 | `ecos `_, 24 | 25 | `numpy `_, 26 | 27 | `pandas `_, 28 | 29 | `plotnine `_, 30 | 31 | `scikit-learn `_, 32 | 33 | `scipy `_, 34 | 35 | `statsmodels `_ 36 | 37 | **scpi_pkg**: scplot 38 | 39 | Usage 40 | ----- 41 | 42 | This example shows how to prepare the data and conduct estimation for synthetic control methods. The raw data can be downloaded 43 | `here `_:: 44 | 45 | import pandas 46 | from scpi_pkg.scdata import scdata 47 | from scpi_pkg.scest import scest 48 | 49 | data = pandas.read_csv("scpi_germany.csv") 50 | 51 | id_var = 'country' 52 | outcome_var = 'gdp' 53 | time_var = 'year' 54 | features = None 55 | cov_adj = None 56 | period_pre = numpy.arange(1960, 1991) 57 | period_post = numpy.arange(1991, 2004) 58 | unit_tr = 'West Germany' 59 | unit_co = list(set(data[id_var].to_list())) 60 | unit_co = [cou for cou in unit_co if cou != 'West Germany'] 61 | constant = True 62 | report_missing = False 63 | cointegrated_data = True 64 | 65 | data_prep = scdata(df=data, id_var=id_var, time_var=time_var, 66 | outcome_var=outcome_var, period_pre=period_pre, 67 | period_post=period_post, unit_tr=unit_tr, 68 | unit_co=unit_co, features=features, cov_adj=cov_adj, 69 | cointegrated_data=cointegrated_data, constant=constant, 70 | report_missing=report_missing) 71 | 72 | # SC - point estimation with simplex 73 | est_si = scest(data_prep, w_constr={'name': "simplex"}) 74 | print(est_si) 75 | est_si2 = scest(data_prep, w_constr={'p': 'L1', 'dir': '==', 'Q': 1, 'lb': 0}) 76 | print(est_si2) 77 | 78 | # SC - point estimation with lasso 79 | est_lasso = scest(data_prep, w_constr={'name': "lasso"}) 80 | print(est_lasso) 81 | est_lasso2 = scest(data_prep, w_constr={'p': 'L1', 'dir': '<=', 'Q': 1, 'lb': -numpy.inf}) 82 | print(est_lasso2) 83 | 84 | est_ridge = scest(data_prep, w_constr={'name': "ridge"}) 85 | print(est_ridge) 86 | Q_est = est_ridge.w_constr['Q'] 87 | est_ridge2 = scest(data_prep, w_constr={'p': 'L2', 'dir': '<=', 'Q': Q_est, 'lb': -numpy.inf}) 88 | print(est_ridge2) 89 | 90 | # SC - point estimation with ols 91 | est_ls = scest(data_prep, w_constr={'name': "ols"}) 92 | print(est_ls) 93 | est_ls2 = scest(data_prep, w_constr={'p': 'no norm', 'dir': None, 'Q': None, 'lb': -numpy.inf}) 94 | print(est_ls2) 95 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_sources/scpi.rst.txt: -------------------------------------------------------------------------------- 1 | Prediction Intervals for Synthetic Control (:py:mod:`scpi.scpi`) 2 | ======================================================================== 3 | 4 | This page describes the function ``scpi`` to implement point estimation and inference procedures for synthetic control methods 5 | using least squares, lasso, ridge, or simplex-type constraints. Uncertainty is quantified using prediction intervals according to 6 | `Cattaneo, Feng, and Titiunik (2021) `_. 7 | The names of the output matrices follow the notation proposed in `Cattaneo, Feng, Palomba, and Titiunik (2022) `_ 8 | 9 | Functions 10 | --------- 11 | 12 | .. currentmodule:: scpi_pkg.scpi 13 | .. autofunction:: scpi 14 | 15 | 16 | Dependencies 17 | ------------ 18 | 19 | **Python**: `cvxpy `_, 20 | 21 | `dask `_, 22 | 23 | `ecos `_, 24 | 25 | `numpy `_, 26 | 27 | `pandas `_, 28 | 29 | `plotnine `_, 30 | 31 | `scikit-learn `_, 32 | 33 | `scipy `_, 34 | 35 | `statsmodels `_ 36 | 37 | **scpi_pkg**: scest, scplot 38 | 39 | Usage 40 | ----- 41 | 42 | This example shows how to prepare the data and estimate prediction intervals for synthetic control methods. The raw data can be downloaded 43 | `here `_:: 44 | 45 | import pandas 46 | from scpi_pkg.scdata import scdata 47 | from scpi_pkg.scpi import scpi 48 | 49 | data = pandas.read_csv("scpi_germany.csv") 50 | 51 | id_var = 'country' 52 | outcome_var = 'gdp' 53 | time_var = 'year' 54 | features = None 55 | cov_adj = None 56 | period_pre = numpy.arange(1960, 1991) 57 | period_post = numpy.arange(1991, 2004) 58 | unit_tr = 'West Germany' 59 | unit_co = list(set(data[id_var].to_list())) 60 | unit_co = [cou for cou in unit_co if cou != 'West Germany'] 61 | constant = True 62 | report_missing = False 63 | cointegrated_data = True 64 | 65 | data_prep = scdata(df=data, id_var=id_var, time_var=time_var, 66 | outcome_var=outcome_var, period_pre=period_pre, 67 | period_post=period_post, unit_tr=unit_tr, 68 | unit_co=unit_co, features=features, cov_adj=cov_adj, 69 | cointegrated_data=cointegrated_data, constant=constant, 70 | report_missing=report_missing) 71 | 72 | # Set options for inference 73 | w_constr = {'name': 'simplex', 'Q': 1} 74 | u_missp = True 75 | u_sigma = "HC1" 76 | u_order = 1 77 | u_lags = 0 78 | e_method = "qreg" 79 | e_order = 1 80 | e_lags = 0 81 | e_alpha = 0.05 82 | u_alpha = 0.05 83 | sims = 500 84 | cores = 1 85 | 86 | pi_si = scpi(data_prep, sims=sims, w_constr=w_constr, u_order=u_order, u_lags=u_lags, 87 | e_order=e_order, e_lags=e_lags, e_method=e_method, u_missp=u_missp, 88 | u_sigma=u_sigma, cores=cores, e_alpha=e_alpha, u_alpha=u_alpha) 89 | print(pi_si) -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_sources/scplot.rst.txt: -------------------------------------------------------------------------------- 1 | Plots for Synthetic Control (:py:mod:`scplot.scplot`) 2 | ======================================================================== 3 | 4 | This page describes the function ``scplot`` to implement several Synthetic Control plots. 5 | The function is designed to be called after ``scest`` or ``scpi`` 6 | which implement estimation and inference procedures for Synthetic Control methods using least squares, lasso, 7 | ridge, or simplex-type constraints according to 8 | `Cattaneo, Feng, and Titiunik (2021) `_ 9 | and `Cattaneo, Feng, Palomba, and Titiunik (2022) `_ 10 | 11 | Syntax 12 | --------- 13 | 14 | .. currentmodule:: scpi_pkg.scplot 15 | .. autofunction:: scplot 16 | 17 | 18 | Dependencies 19 | ------------ 20 | 21 | **Python**: `cvxpy `_, 22 | 23 | `dask `_, 24 | 25 | `ecos `_, 26 | 27 | `numpy `_, 28 | 29 | `pandas `_, 30 | 31 | `plotnine `_, 32 | 33 | `scikit-learn `_, 34 | 35 | `scipy `_, 36 | 37 | `statsmodels `_ 38 | 39 | **scpi_pkg**: none 40 | 41 | Usage 42 | ----- 43 | 44 | This example shows how to prepare the data and conduct estimation for synthetic control methods. The raw data can be downloaded 45 | `here `_:: 46 | 47 | import pandas 48 | from scpi_pkg.scdata import scdata 49 | from scpi_pkg.scest import scest 50 | from scpi_pkg.scplot import scplot 51 | 52 | data = pandas.read_csv("scpi_germany.csv") 53 | 54 | id_var = 'country' 55 | outcome_var = 'gdp' 56 | time_var = 'year' 57 | features = None 58 | cov_adj = None 59 | period_pre = numpy.arange(1960, 1991) 60 | period_post = numpy.arange(1991, 2004) 61 | unit_tr = 'West Germany' 62 | unit_co = list(set(data[id_var].to_list())) 63 | unit_co = [cou for cou in unit_co if cou != 'West Germany'] 64 | constant = True 65 | report_missing = False 66 | cointegrated_data = True 67 | 68 | data_prep = scdata(df=data, id_var=id_var, time_var=time_var, 69 | outcome_var=outcome_var, period_pre=period_pre, 70 | period_post=period_post, unit_tr=unit_tr, 71 | unit_co=unit_co, features=features, cov_adj=cov_adj, 72 | cointegrated_data=cointegrated_data, constant=constant, 73 | report_missing=report_missing) 74 | 75 | # SC - point estimation with simplex 76 | est_si = scest(data_prep, w_constr={'name': "simplex"}) 77 | print(est_si) 78 | 79 | plot = scplot(est_si) 80 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_sources/scplotMulti.rst.txt: -------------------------------------------------------------------------------- 1 | Plots for Synthetic Control with Multiple Treated Units (:py:mod:`scplotMulti.scplotMulti`) 2 | =============================================================================================== 3 | 4 | This page describes the function ``scplotMulti`` to implement several Synthetic Control plots when Multiple 5 | treated units and staggered adoption are features of the design. 6 | The function is designed to be called after ``scest`` or ``scpi`` 7 | which implement estimation and inference procedures for Synthetic Control methods using least squares, lasso, 8 | ridge, or simplex-type constraints according to 9 | `Cattaneo, Feng, and Titiunik (2021) `_ 10 | and `Cattaneo, Feng, Palomba, and Titiunik (2022) `_ 11 | 12 | Syntax 13 | --------- 14 | 15 | .. currentmodule:: scpi_pkg.scplotMulti 16 | .. autofunction:: scplotMulti 17 | 18 | 19 | Dependencies 20 | ------------ 21 | 22 | **Python**: `cvxpy `_, 23 | 24 | `dask `_, 25 | 26 | `ecos `_, 27 | 28 | `numpy `_, 29 | 30 | `pandas `_, 31 | 32 | `plotnine `_, 33 | 34 | `scikit-learn `_, 35 | 36 | `scipy `_, 37 | 38 | `statsmodels `_ 39 | 40 | **scpi_pkg**: none 41 | 42 | Usage 43 | ----- 44 | 45 | This example shows how to prepare the data and conduct estimation for synthetic control methods. The raw data can be downloaded 46 | `here `_:: 47 | 48 | import pandas 49 | from scdataMulti import scdataMulti 50 | from scest import scest 51 | from scplotMulti import scplotMulti 52 | 53 | df = pandas.read_csv("scpi_germany.csv") 54 | 55 | # Create a second placebo treated unit 56 | df.loc[(df['country'] == "Italy") & (df['year'] >= 1992), 'status'] = 1 57 | 58 | # same features for all treated units 59 | features = {'anyname': [list of variables to match on]} 60 | 61 | # same covariate adjustment for all treated units for all features 62 | cov_adj = {'anyname': ['constant', 'trend']} 63 | 64 | # unit specific presence of global constant 65 | constant = {'treated_1': True, 'treated_2': False} 66 | 67 | # unit specific presence of cointegration 68 | cointegrated_data = {'treated_1': True, 'treated_2': False} 69 | 70 | # unit specific presence of anticipation effects 71 | anticipation = {'treated_1': 0, 'treated_2': 1} 72 | 73 | aux = scdataMulti(df=df, 74 | id_var='country', 75 | treatment_var='treatment', 76 | outcome_var='gdp', 77 | time_var='year', 78 | features=features, 79 | constant=constant, 80 | anticipation=anticipation, 81 | cointegrated_data=cointegrated_data) 82 | 83 | res = scest(aux) 84 | 85 | scplotMulti(res) 86 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/_sphinx_javascript_frameworks_compat.js: -------------------------------------------------------------------------------- 1 | /* 2 | * _sphinx_javascript_frameworks_compat.js 3 | * ~~~~~~~~~~ 4 | * 5 | * Compatability shim for jQuery and underscores.js. 6 | * 7 | * WILL BE REMOVED IN Sphinx 6.0 8 | * xref RemovedInSphinx60Warning 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | 18 | /** 19 | * small helper function to urldecode strings 20 | * 21 | * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent#Decoding_query_parameters_from_a_URL 22 | */ 23 | jQuery.urldecode = function(x) { 24 | if (!x) { 25 | return x 26 | } 27 | return decodeURIComponent(x.replace(/\+/g, ' ')); 28 | }; 29 | 30 | /** 31 | * small helper function to urlencode strings 32 | */ 33 | jQuery.urlencode = encodeURIComponent; 34 | 35 | /** 36 | * This function returns the parsed url parameters of the 37 | * current request. Multiple values per key are supported, 38 | * it will always return arrays of strings for the value parts. 39 | */ 40 | jQuery.getQueryParameters = function(s) { 41 | if (typeof s === 'undefined') 42 | s = document.location.search; 43 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 44 | var result = {}; 45 | for (var i = 0; i < parts.length; i++) { 46 | var tmp = parts[i].split('=', 2); 47 | var key = jQuery.urldecode(tmp[0]); 48 | var value = jQuery.urldecode(tmp[1]); 49 | if (key in result) 50 | result[key].push(value); 51 | else 52 | result[key] = [value]; 53 | } 54 | return result; 55 | }; 56 | 57 | /** 58 | * highlight a given string on a jquery object by wrapping it in 59 | * span elements with the given class name. 60 | */ 61 | jQuery.fn.highlightText = function(text, className) { 62 | function highlight(node, addItems) { 63 | if (node.nodeType === 3) { 64 | var val = node.nodeValue; 65 | var pos = val.toLowerCase().indexOf(text); 66 | if (pos >= 0 && 67 | !jQuery(node.parentNode).hasClass(className) && 68 | !jQuery(node.parentNode).hasClass("nohighlight")) { 69 | var span; 70 | var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg"); 71 | if (isInSVG) { 72 | span = document.createElementNS("http://www.w3.org/2000/svg", "tspan"); 73 | } else { 74 | span = document.createElement("span"); 75 | span.className = className; 76 | } 77 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 78 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 79 | document.createTextNode(val.substr(pos + text.length)), 80 | node.nextSibling)); 81 | node.nodeValue = val.substr(0, pos); 82 | if (isInSVG) { 83 | var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect"); 84 | var bbox = node.parentElement.getBBox(); 85 | rect.x.baseVal.value = bbox.x; 86 | rect.y.baseVal.value = bbox.y; 87 | rect.width.baseVal.value = bbox.width; 88 | rect.height.baseVal.value = bbox.height; 89 | rect.setAttribute('class', className); 90 | addItems.push({ 91 | "parent": node.parentNode, 92 | "target": rect}); 93 | } 94 | } 95 | } 96 | else if (!jQuery(node).is("button, select, textarea")) { 97 | jQuery.each(node.childNodes, function() { 98 | highlight(this, addItems); 99 | }); 100 | } 101 | } 102 | var addItems = []; 103 | var result = this.each(function() { 104 | highlight(this, addItems); 105 | }); 106 | for (var i = 0; i < addItems.length; ++i) { 107 | jQuery(addItems[i].parent).before(addItems[i].target); 108 | } 109 | return result; 110 | }; 111 | 112 | /* 113 | * backward compatibility for jQuery.browser 114 | * This will be supported until firefox bug is fixed. 115 | */ 116 | if (!jQuery.browser) { 117 | jQuery.uaMatch = function(ua) { 118 | ua = ua.toLowerCase(); 119 | 120 | var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || 121 | /(webkit)[ \/]([\w.]+)/.exec(ua) || 122 | /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || 123 | /(msie) ([\w.]+)/.exec(ua) || 124 | ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || 125 | []; 126 | 127 | return { 128 | browser: match[ 1 ] || "", 129 | version: match[ 2 ] || "0" 130 | }; 131 | }; 132 | jQuery.browser = {}; 133 | jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true; 134 | } 135 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .clearfix{*zoom:1}.clearfix:after,.clearfix:before{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-style:normal;font-weight:400;src:url(fonts/fontawesome-webfont.eot?674f50d287a8c48dc19ba404d20fe713?#iefix) format("embedded-opentype"),url(fonts/fontawesome-webfont.woff2?af7ae505a9eed503f8b8e6982036873e) format("woff2"),url(fonts/fontawesome-webfont.woff?fee66e712a8a08eef5805a46892932ad) format("woff"),url(fonts/fontawesome-webfont.ttf?b06871f281fee6b241d60582ae9369b9) format("truetype"),url(fonts/fontawesome-webfont.svg?912ec66d7572ff821749319396470bde#FontAwesome) format("svg")}.fa:before{font-family:FontAwesome;font-style:normal;font-weight:400;line-height:1}.fa:before,a .fa{text-decoration:inherit}.fa:before,a .fa,li .fa{display:inline-block}li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-.8em}ul.fas li .fa{width:.8em}ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before,.icon-book:before{content:"\f02d"}.fa-caret-down:before,.icon-caret-down:before{content:"\f0d7"}.fa-caret-up:before,.icon-caret-up:before{content:"\f0d8"}.fa-caret-left:before,.icon-caret-left:before{content:"\f0d9"}.fa-caret-right:before,.icon-caret-right:before{content:"\f0da"}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;font-family:Lato,proxima-nova,Helvetica Neue,Arial,sans-serif;z-index:400}.rst-versions a{color:#2980b9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27ae60}.rst-versions .rst-current-version:after{clear:both;content:"";display:block}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book,.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#e74c3c;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#f1c40f;color:#000}.rst-versions.shift-up{height:auto;max-height:100%;overflow-y:scroll}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:grey;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:1px solid #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px;max-height:90%}.rst-versions.rst-badge .fa-book,.rst-versions.rst-badge .icon-book{float:none;line-height:30px}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book,.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge>.rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width:768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}} -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff2 -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff2 -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-bold-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-bold-italic.woff -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-bold-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-bold-italic.woff2 -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-bold.woff -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-bold.woff2 -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-normal-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-normal-italic.woff -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-normal-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-normal-italic.woff2 -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-normal.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-normal.woff -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-normal.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/css/fonts/lato-normal.woff2 -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Base JavaScript utilities for all Sphinx HTML documentation. 6 | * 7 | * :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | "use strict"; 12 | 13 | const BLACKLISTED_KEY_CONTROL_ELEMENTS = new Set([ 14 | "TEXTAREA", 15 | "INPUT", 16 | "SELECT", 17 | "BUTTON", 18 | ]); 19 | 20 | const _ready = (callback) => { 21 | if (document.readyState !== "loading") { 22 | callback(); 23 | } else { 24 | document.addEventListener("DOMContentLoaded", callback); 25 | } 26 | }; 27 | 28 | /** 29 | * Small JavaScript module for the documentation. 30 | */ 31 | const Documentation = { 32 | init: () => { 33 | Documentation.initDomainIndexTable(); 34 | Documentation.initOnKeyListeners(); 35 | }, 36 | 37 | /** 38 | * i18n support 39 | */ 40 | TRANSLATIONS: {}, 41 | PLURAL_EXPR: (n) => (n === 1 ? 0 : 1), 42 | LOCALE: "unknown", 43 | 44 | // gettext and ngettext don't access this so that the functions 45 | // can safely bound to a different name (_ = Documentation.gettext) 46 | gettext: (string) => { 47 | const translated = Documentation.TRANSLATIONS[string]; 48 | switch (typeof translated) { 49 | case "undefined": 50 | return string; // no translation 51 | case "string": 52 | return translated; // translation exists 53 | default: 54 | return translated[0]; // (singular, plural) translation tuple exists 55 | } 56 | }, 57 | 58 | ngettext: (singular, plural, n) => { 59 | const translated = Documentation.TRANSLATIONS[singular]; 60 | if (typeof translated !== "undefined") 61 | return translated[Documentation.PLURAL_EXPR(n)]; 62 | return n === 1 ? singular : plural; 63 | }, 64 | 65 | addTranslations: (catalog) => { 66 | Object.assign(Documentation.TRANSLATIONS, catalog.messages); 67 | Documentation.PLURAL_EXPR = new Function( 68 | "n", 69 | `return (${catalog.plural_expr})` 70 | ); 71 | Documentation.LOCALE = catalog.locale; 72 | }, 73 | 74 | /** 75 | * helper function to focus on search bar 76 | */ 77 | focusSearchBar: () => { 78 | document.querySelectorAll("input[name=q]")[0]?.focus(); 79 | }, 80 | 81 | /** 82 | * Initialise the domain index toggle buttons 83 | */ 84 | initDomainIndexTable: () => { 85 | const toggler = (el) => { 86 | const idNumber = el.id.substr(7); 87 | const toggledRows = document.querySelectorAll(`tr.cg-${idNumber}`); 88 | if (el.src.substr(-9) === "minus.png") { 89 | el.src = `${el.src.substr(0, el.src.length - 9)}plus.png`; 90 | toggledRows.forEach((el) => (el.style.display = "none")); 91 | } else { 92 | el.src = `${el.src.substr(0, el.src.length - 8)}minus.png`; 93 | toggledRows.forEach((el) => (el.style.display = "")); 94 | } 95 | }; 96 | 97 | const togglerElements = document.querySelectorAll("img.toggler"); 98 | togglerElements.forEach((el) => 99 | el.addEventListener("click", (event) => toggler(event.currentTarget)) 100 | ); 101 | togglerElements.forEach((el) => (el.style.display = "")); 102 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) togglerElements.forEach(toggler); 103 | }, 104 | 105 | initOnKeyListeners: () => { 106 | // only install a listener if it is really needed 107 | if ( 108 | !DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS && 109 | !DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS 110 | ) 111 | return; 112 | 113 | document.addEventListener("keydown", (event) => { 114 | // bail for input elements 115 | if (BLACKLISTED_KEY_CONTROL_ELEMENTS.has(document.activeElement.tagName)) return; 116 | // bail with special keys 117 | if (event.altKey || event.ctrlKey || event.metaKey) return; 118 | 119 | if (!event.shiftKey) { 120 | switch (event.key) { 121 | case "ArrowLeft": 122 | if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) break; 123 | 124 | const prevLink = document.querySelector('link[rel="prev"]'); 125 | if (prevLink && prevLink.href) { 126 | window.location.href = prevLink.href; 127 | event.preventDefault(); 128 | } 129 | break; 130 | case "ArrowRight": 131 | if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) break; 132 | 133 | const nextLink = document.querySelector('link[rel="next"]'); 134 | if (nextLink && nextLink.href) { 135 | window.location.href = nextLink.href; 136 | event.preventDefault(); 137 | } 138 | break; 139 | } 140 | } 141 | 142 | // some keyboard layouts may need Shift to get / 143 | switch (event.key) { 144 | case "/": 145 | if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS) break; 146 | Documentation.focusSearchBar(); 147 | event.preventDefault(); 148 | } 149 | }); 150 | }, 151 | }; 152 | 153 | // quick alias for translations 154 | const _ = Documentation.gettext; 155 | 156 | _ready(Documentation.init); 157 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/documentation_options.js: -------------------------------------------------------------------------------- 1 | var DOCUMENTATION_OPTIONS = { 2 | URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), 3 | VERSION: '2.2.2', 4 | LANGUAGE: 'en', 5 | COLLAPSE_INDEX: false, 6 | BUILDER: 'html', 7 | FILE_SUFFIX: '.html', 8 | LINK_SUFFIX: '.html', 9 | HAS_SOURCE: true, 10 | SOURCELINK_SUFFIX: '.txt', 11 | NAVIGATION_WITH_KEYS: false, 12 | SHOW_SEARCH_SUMMARY: true, 13 | ENABLE_SEARCH_SHORTCUTS: true, 14 | }; -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/file.png -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/js/badge_only.js: -------------------------------------------------------------------------------- 1 | !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}({4:function(e,t,r){}}); -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/js/html5shiv-printshiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3-pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=y.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=y.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),y.elements=c+" "+a,j(b)}function f(a){var b=x[a[v]];return b||(b={},w++,a[v]=w,x[w]=b),b}function g(a,c,d){if(c||(c=b),q)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():u.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||t.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),q)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return y.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(y,b.frag)}function j(a){a||(a=b);var d=f(a);return!y.shivCSS||p||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),q||i(a,d),a}function k(a){for(var b,c=a.getElementsByTagName("*"),e=c.length,f=RegExp("^(?:"+d().join("|")+")$","i"),g=[];e--;)b=c[e],f.test(b.nodeName)&&g.push(b.applyElement(l(b)));return g}function l(a){for(var b,c=a.attributes,d=c.length,e=a.ownerDocument.createElement(A+":"+a.nodeName);d--;)b=c[d],b.specified&&e.setAttribute(b.nodeName,b.nodeValue);return e.style.cssText=a.style.cssText,e}function m(a){for(var b,c=a.split("{"),e=c.length,f=RegExp("(^|[\\s,>+~])("+d().join("|")+")(?=[[\\s,>+~#.:]|$)","gi"),g="$1"+A+"\\:$2";e--;)b=c[e]=c[e].split("}"),b[b.length-1]=b[b.length-1].replace(f,g),c[e]=b.join("}");return c.join("{")}function n(a){for(var b=a.length;b--;)a[b].removeNode()}function o(a){function b(){clearTimeout(g._removeSheetTimer),d&&d.removeNode(!0),d=null}var d,e,g=f(a),h=a.namespaces,i=a.parentWindow;return!B||a.printShived?a:("undefined"==typeof h[A]&&h.add(A),i.attachEvent("onbeforeprint",function(){b();for(var f,g,h,i=a.styleSheets,j=[],l=i.length,n=Array(l);l--;)n[l]=i[l];for(;h=n.pop();)if(!h.disabled&&z.test(h.media)){try{f=h.imports,g=f.length}catch(o){g=0}for(l=0;g>l;l++)n.push(f[l]);try{j.push(h.cssText)}catch(o){}}j=m(j.reverse().join("")),e=k(a),d=c(a,j)}),i.attachEvent("onafterprint",function(){n(e),clearTimeout(g._removeSheetTimer),g._removeSheetTimer=setTimeout(b,500)}),a.printShived=!0,a)}var p,q,r="3.7.3",s=a.html5||{},t=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,u=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,v="_html5shiv",w=0,x={};!function(){try{var a=b.createElement("a");a.innerHTML="",p="hidden"in a,q=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){p=!0,q=!0}}();var y={elements:s.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:r,shivCSS:s.shivCSS!==!1,supportsUnknownElements:q,shivMethods:s.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=y,j(b);var z=/^$|\b(?:all|print)\b/,A="html5shiv",B=!q&&function(){var c=b.documentElement;return!("undefined"==typeof b.namespaces||"undefined"==typeof b.parentWindow||"undefined"==typeof c.applyElement||"undefined"==typeof c.removeNode||"undefined"==typeof a.attachEvent)}();y.type+=" print",y.shivPrint=o,o(b),"object"==typeof module&&module.exports&&(module.exports=y)}("undefined"!=typeof window?window:this,document); -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/js/html5shiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=t.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=t.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),t.elements=c+" "+a,j(b)}function f(a){var b=s[a[q]];return b||(b={},r++,a[q]=r,s[r]=b),b}function g(a,c,d){if(c||(c=b),l)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():p.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||o.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),l)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return t.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(t,b.frag)}function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.3-pre",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b),"object"==typeof module&&module.exports&&(module.exports=t)}("undefined"!=typeof window?window:this,document); -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/js/theme.js: -------------------------------------------------------------------------------- 1 | !function(n){var e={};function t(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return n[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=n,t.c=e,t.d=function(n,e,i){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:i})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var i=Object.create(null);if(t.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)t.d(i,o,function(e){return n[e]}.bind(null,o));return i},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=0)}([function(n,e,t){t(1),n.exports=t(3)},function(n,e,t){(function(){var e="undefined"!=typeof window?window.jQuery:t(2);n.exports.ThemeNav={navBar:null,win:null,winScroll:!1,winResize:!1,linkScroll:!1,winPosition:0,winHeight:null,docHeight:null,isRunning:!1,enable:function(n){var t=this;void 0===n&&(n=!0),t.isRunning||(t.isRunning=!0,e((function(e){t.init(e),t.reset(),t.win.on("hashchange",t.reset),n&&t.win.on("scroll",(function(){t.linkScroll||t.winScroll||(t.winScroll=!0,requestAnimationFrame((function(){t.onScroll()})))})),t.win.on("resize",(function(){t.winResize||(t.winResize=!0,requestAnimationFrame((function(){t.onResize()})))})),t.onResize()})))},enableSticky:function(){this.enable(!0)},init:function(n){n(document);var e=this;this.navBar=n("div.wy-side-scroll:first"),this.win=n(window),n(document).on("click","[data-toggle='wy-nav-top']",(function(){n("[data-toggle='wy-nav-shift']").toggleClass("shift"),n("[data-toggle='rst-versions']").toggleClass("shift")})).on("click",".wy-menu-vertical .current ul li a",(function(){var t=n(this);n("[data-toggle='wy-nav-shift']").removeClass("shift"),n("[data-toggle='rst-versions']").toggleClass("shift"),e.toggleCurrent(t),e.hashChange()})).on("click","[data-toggle='rst-current-version']",(function(){n("[data-toggle='rst-versions']").toggleClass("shift-up")})),n("table.docutils:not(.field-list,.footnote,.citation)").wrap("
"),n("table.docutils.footnote").wrap("
"),n("table.docutils.citation").wrap("
"),n(".wy-menu-vertical ul").not(".simple").siblings("a").each((function(){var t=n(this);expand=n(''),expand.on("click",(function(n){return e.toggleCurrent(t),n.stopPropagation(),!1})),t.prepend(expand)}))},reset:function(){var n=encodeURI(window.location.hash)||"#";try{var e=$(".wy-menu-vertical"),t=e.find('[href="'+n+'"]');if(0===t.length){var i=$('.document [id="'+n.substring(1)+'"]').closest("div.section");0===(t=e.find('[href="#'+i.attr("id")+'"]')).length&&(t=e.find('[href="#"]'))}if(t.length>0){$(".wy-menu-vertical .current").removeClass("current").attr("aria-expanded","false"),t.addClass("current").attr("aria-expanded","true"),t.closest("li.toctree-l1").parent().addClass("current").attr("aria-expanded","true");for(let n=1;n<=10;n++)t.closest("li.toctree-l"+n).addClass("current").attr("aria-expanded","true");t[0].scrollIntoView()}}catch(n){console.log("Error expanding nav for anchor",n)}},onScroll:function(){this.winScroll=!1;var n=this.win.scrollTop(),e=n+this.winHeight,t=this.navBar.scrollTop()+(n-this.winPosition);n<0||e>this.docHeight||(this.navBar.scrollTop(t),this.winPosition=n)},onResize:function(){this.winResize=!1,this.winHeight=this.win.height(),this.docHeight=$(document).height()},hashChange:function(){this.linkScroll=!0,this.win.one("hashchange",(function(){this.linkScroll=!1}))},toggleCurrent:function(n){var e=n.closest("li");e.siblings("li.current").removeClass("current").attr("aria-expanded","false"),e.siblings().find("li.current").removeClass("current").attr("aria-expanded","false");var t=e.find("> ul li");t.length&&(t.removeClass("current").attr("aria-expanded","false"),e.toggleClass("current").attr("aria-expanded",(function(n,e){return"true"==e?"false":"true"})))}},"undefined"!=typeof window&&(window.SphinxRtdTheme={Navigation:n.exports.ThemeNav,StickyNav:n.exports.ThemeNav}),function(){for(var n=0,e=["ms","moz","webkit","o"],t=0;t0 63 | var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1 64 | var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1 65 | var s_v = "^(" + C + ")?" + v; // vowel in stem 66 | 67 | this.stemWord = function (w) { 68 | var stem; 69 | var suffix; 70 | var firstch; 71 | var origword = w; 72 | 73 | if (w.length < 3) 74 | return w; 75 | 76 | var re; 77 | var re2; 78 | var re3; 79 | var re4; 80 | 81 | firstch = w.substr(0,1); 82 | if (firstch == "y") 83 | w = firstch.toUpperCase() + w.substr(1); 84 | 85 | // Step 1a 86 | re = /^(.+?)(ss|i)es$/; 87 | re2 = /^(.+?)([^s])s$/; 88 | 89 | if (re.test(w)) 90 | w = w.replace(re,"$1$2"); 91 | else if (re2.test(w)) 92 | w = w.replace(re2,"$1$2"); 93 | 94 | // Step 1b 95 | re = /^(.+?)eed$/; 96 | re2 = /^(.+?)(ed|ing)$/; 97 | if (re.test(w)) { 98 | var fp = re.exec(w); 99 | re = new RegExp(mgr0); 100 | if (re.test(fp[1])) { 101 | re = /.$/; 102 | w = w.replace(re,""); 103 | } 104 | } 105 | else if (re2.test(w)) { 106 | var fp = re2.exec(w); 107 | stem = fp[1]; 108 | re2 = new RegExp(s_v); 109 | if (re2.test(stem)) { 110 | w = stem; 111 | re2 = /(at|bl|iz)$/; 112 | re3 = new RegExp("([^aeiouylsz])\\1$"); 113 | re4 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 114 | if (re2.test(w)) 115 | w = w + "e"; 116 | else if (re3.test(w)) { 117 | re = /.$/; 118 | w = w.replace(re,""); 119 | } 120 | else if (re4.test(w)) 121 | w = w + "e"; 122 | } 123 | } 124 | 125 | // Step 1c 126 | re = /^(.+?)y$/; 127 | if (re.test(w)) { 128 | var fp = re.exec(w); 129 | stem = fp[1]; 130 | re = new RegExp(s_v); 131 | if (re.test(stem)) 132 | w = stem + "i"; 133 | } 134 | 135 | // Step 2 136 | re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/; 137 | if (re.test(w)) { 138 | var fp = re.exec(w); 139 | stem = fp[1]; 140 | suffix = fp[2]; 141 | re = new RegExp(mgr0); 142 | if (re.test(stem)) 143 | w = stem + step2list[suffix]; 144 | } 145 | 146 | // Step 3 147 | re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/; 148 | if (re.test(w)) { 149 | var fp = re.exec(w); 150 | stem = fp[1]; 151 | suffix = fp[2]; 152 | re = new RegExp(mgr0); 153 | if (re.test(stem)) 154 | w = stem + step3list[suffix]; 155 | } 156 | 157 | // Step 4 158 | re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/; 159 | re2 = /^(.+?)(s|t)(ion)$/; 160 | if (re.test(w)) { 161 | var fp = re.exec(w); 162 | stem = fp[1]; 163 | re = new RegExp(mgr1); 164 | if (re.test(stem)) 165 | w = stem; 166 | } 167 | else if (re2.test(w)) { 168 | var fp = re2.exec(w); 169 | stem = fp[1] + fp[2]; 170 | re2 = new RegExp(mgr1); 171 | if (re2.test(stem)) 172 | w = stem; 173 | } 174 | 175 | // Step 5 176 | re = /^(.+?)e$/; 177 | if (re.test(w)) { 178 | var fp = re.exec(w); 179 | stem = fp[1]; 180 | re = new RegExp(mgr1); 181 | re2 = new RegExp(meq1); 182 | re3 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 183 | if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) 184 | w = stem; 185 | } 186 | re = /ll$/; 187 | re2 = new RegExp(mgr1); 188 | if (re.test(w) && re2.test(w)) { 189 | re = /.$/; 190 | w = w.replace(re,""); 191 | } 192 | 193 | // and turn initial Y back to y 194 | if (firstch == "y") 195 | w = firstch.toLowerCase() + w.substr(1); 196 | return w; 197 | } 198 | } 199 | 200 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/minus.png -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/_static/plus.png -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/pygments.css: -------------------------------------------------------------------------------- 1 | pre { line-height: 125%; } 2 | td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } 3 | span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } 4 | td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } 5 | span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } 6 | .highlight .hll { background-color: #ffffcc } 7 | .highlight { background: #f8f8f8; } 8 | .highlight .c { color: #3D7B7B; font-style: italic } /* Comment */ 9 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 10 | .highlight .k { color: #008000; font-weight: bold } /* Keyword */ 11 | .highlight .o { color: #666666 } /* Operator */ 12 | .highlight .ch { color: #3D7B7B; font-style: italic } /* Comment.Hashbang */ 13 | .highlight .cm { color: #3D7B7B; font-style: italic } /* Comment.Multiline */ 14 | .highlight .cp { color: #9C6500 } /* Comment.Preproc */ 15 | .highlight .cpf { color: #3D7B7B; font-style: italic } /* Comment.PreprocFile */ 16 | .highlight .c1 { color: #3D7B7B; font-style: italic } /* Comment.Single */ 17 | .highlight .cs { color: #3D7B7B; font-style: italic } /* Comment.Special */ 18 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 19 | .highlight .ge { font-style: italic } /* Generic.Emph */ 20 | .highlight .gr { color: #E40000 } /* Generic.Error */ 21 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 22 | .highlight .gi { color: #008400 } /* Generic.Inserted */ 23 | .highlight .go { color: #717171 } /* Generic.Output */ 24 | .highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ 25 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 26 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 27 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 28 | .highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */ 29 | .highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */ 30 | .highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */ 31 | .highlight .kp { color: #008000 } /* Keyword.Pseudo */ 32 | .highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */ 33 | .highlight .kt { color: #B00040 } /* Keyword.Type */ 34 | .highlight .m { color: #666666 } /* Literal.Number */ 35 | .highlight .s { color: #BA2121 } /* Literal.String */ 36 | .highlight .na { color: #687822 } /* Name.Attribute */ 37 | .highlight .nb { color: #008000 } /* Name.Builtin */ 38 | .highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */ 39 | .highlight .no { color: #880000 } /* Name.Constant */ 40 | .highlight .nd { color: #AA22FF } /* Name.Decorator */ 41 | .highlight .ni { color: #717171; font-weight: bold } /* Name.Entity */ 42 | .highlight .ne { color: #CB3F38; font-weight: bold } /* Name.Exception */ 43 | .highlight .nf { color: #0000FF } /* Name.Function */ 44 | .highlight .nl { color: #767600 } /* Name.Label */ 45 | .highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ 46 | .highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */ 47 | .highlight .nv { color: #19177C } /* Name.Variable */ 48 | .highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ 49 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 50 | .highlight .mb { color: #666666 } /* Literal.Number.Bin */ 51 | .highlight .mf { color: #666666 } /* Literal.Number.Float */ 52 | .highlight .mh { color: #666666 } /* Literal.Number.Hex */ 53 | .highlight .mi { color: #666666 } /* Literal.Number.Integer */ 54 | .highlight .mo { color: #666666 } /* Literal.Number.Oct */ 55 | .highlight .sa { color: #BA2121 } /* Literal.String.Affix */ 56 | .highlight .sb { color: #BA2121 } /* Literal.String.Backtick */ 57 | .highlight .sc { color: #BA2121 } /* Literal.String.Char */ 58 | .highlight .dl { color: #BA2121 } /* Literal.String.Delimiter */ 59 | .highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */ 60 | .highlight .s2 { color: #BA2121 } /* Literal.String.Double */ 61 | .highlight .se { color: #AA5D1F; font-weight: bold } /* Literal.String.Escape */ 62 | .highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */ 63 | .highlight .si { color: #A45A77; font-weight: bold } /* Literal.String.Interpol */ 64 | .highlight .sx { color: #008000 } /* Literal.String.Other */ 65 | .highlight .sr { color: #A45A77 } /* Literal.String.Regex */ 66 | .highlight .s1 { color: #BA2121 } /* Literal.String.Single */ 67 | .highlight .ss { color: #19177C } /* Literal.String.Symbol */ 68 | .highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */ 69 | .highlight .fm { color: #0000FF } /* Name.Function.Magic */ 70 | .highlight .vc { color: #19177C } /* Name.Variable.Class */ 71 | .highlight .vg { color: #19177C } /* Name.Variable.Global */ 72 | .highlight .vi { color: #19177C } /* Name.Variable.Instance */ 73 | .highlight .vm { color: #19177C } /* Name.Variable.Magic */ 74 | .highlight .il { color: #666666 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/_static/sphinx_highlight.js: -------------------------------------------------------------------------------- 1 | /* Highlighting utilities for Sphinx HTML documentation. */ 2 | "use strict"; 3 | 4 | const SPHINX_HIGHLIGHT_ENABLED = true 5 | 6 | /** 7 | * highlight a given string on a node by wrapping it in 8 | * span elements with the given class name. 9 | */ 10 | const _highlight = (node, addItems, text, className) => { 11 | if (node.nodeType === Node.TEXT_NODE) { 12 | const val = node.nodeValue; 13 | const parent = node.parentNode; 14 | const pos = val.toLowerCase().indexOf(text); 15 | if ( 16 | pos >= 0 && 17 | !parent.classList.contains(className) && 18 | !parent.classList.contains("nohighlight") 19 | ) { 20 | let span; 21 | 22 | const closestNode = parent.closest("body, svg, foreignObject"); 23 | const isInSVG = closestNode && closestNode.matches("svg"); 24 | if (isInSVG) { 25 | span = document.createElementNS("http://www.w3.org/2000/svg", "tspan"); 26 | } else { 27 | span = document.createElement("span"); 28 | span.classList.add(className); 29 | } 30 | 31 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 32 | parent.insertBefore( 33 | span, 34 | parent.insertBefore( 35 | document.createTextNode(val.substr(pos + text.length)), 36 | node.nextSibling 37 | ) 38 | ); 39 | node.nodeValue = val.substr(0, pos); 40 | 41 | if (isInSVG) { 42 | const rect = document.createElementNS( 43 | "http://www.w3.org/2000/svg", 44 | "rect" 45 | ); 46 | const bbox = parent.getBBox(); 47 | rect.x.baseVal.value = bbox.x; 48 | rect.y.baseVal.value = bbox.y; 49 | rect.width.baseVal.value = bbox.width; 50 | rect.height.baseVal.value = bbox.height; 51 | rect.setAttribute("class", className); 52 | addItems.push({ parent: parent, target: rect }); 53 | } 54 | } 55 | } else if (node.matches && !node.matches("button, select, textarea")) { 56 | node.childNodes.forEach((el) => _highlight(el, addItems, text, className)); 57 | } 58 | }; 59 | const _highlightText = (thisNode, text, className) => { 60 | let addItems = []; 61 | _highlight(thisNode, addItems, text, className); 62 | addItems.forEach((obj) => 63 | obj.parent.insertAdjacentElement("beforebegin", obj.target) 64 | ); 65 | }; 66 | 67 | /** 68 | * Small JavaScript module for the documentation. 69 | */ 70 | const SphinxHighlight = { 71 | 72 | /** 73 | * highlight the search words provided in localstorage in the text 74 | */ 75 | highlightSearchWords: () => { 76 | if (!SPHINX_HIGHLIGHT_ENABLED) return; // bail if no highlight 77 | 78 | // get and clear terms from localstorage 79 | const url = new URL(window.location); 80 | const highlight = 81 | localStorage.getItem("sphinx_highlight_terms") 82 | || url.searchParams.get("highlight") 83 | || ""; 84 | localStorage.removeItem("sphinx_highlight_terms") 85 | url.searchParams.delete("highlight"); 86 | window.history.replaceState({}, "", url); 87 | 88 | // get individual terms from highlight string 89 | const terms = highlight.toLowerCase().split(/\s+/).filter(x => x); 90 | if (terms.length === 0) return; // nothing to do 91 | 92 | // There should never be more than one element matching "div.body" 93 | const divBody = document.querySelectorAll("div.body"); 94 | const body = divBody.length ? divBody[0] : document.querySelector("body"); 95 | window.setTimeout(() => { 96 | terms.forEach((term) => _highlightText(body, term, "highlighted")); 97 | }, 10); 98 | 99 | const searchBox = document.getElementById("searchbox"); 100 | if (searchBox === null) return; 101 | searchBox.appendChild( 102 | document 103 | .createRange() 104 | .createContextualFragment( 105 | '" 109 | ) 110 | ); 111 | }, 112 | 113 | /** 114 | * helper function to hide the search marks again 115 | */ 116 | hideSearchWords: () => { 117 | document 118 | .querySelectorAll("#searchbox .highlight-link") 119 | .forEach((el) => el.remove()); 120 | document 121 | .querySelectorAll("span.highlighted") 122 | .forEach((el) => el.classList.remove("highlighted")); 123 | localStorage.removeItem("sphinx_highlight_terms") 124 | }, 125 | 126 | initEscapeListener: () => { 127 | // only install a listener if it is really needed 128 | if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS) return; 129 | 130 | document.addEventListener("keydown", (event) => { 131 | // bail for input elements 132 | if (BLACKLISTED_KEY_CONTROL_ELEMENTS.has(document.activeElement.tagName)) return; 133 | // bail with special keys 134 | if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return; 135 | if (DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS && (event.key === "Escape")) { 136 | SphinxHighlight.hideSearchWords(); 137 | event.preventDefault(); 138 | } 139 | }); 140 | }, 141 | }; 142 | 143 | _ready(SphinxHighlight.highlightSearchWords); 144 | _ready(SphinxHighlight.initEscapeListener); 145 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/docs/_build/html/objects.inv -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/_build/html/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Search — scpi-pkg 2.2.2 documentation 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 60 | 61 |
65 | 66 |
67 |
68 |
69 |
    70 |
  • 71 | 72 |
  • 73 |
  • 74 |
75 |
76 |
77 |
78 |
79 | 80 | 87 | 88 | 89 |
90 | 91 |
92 | 93 |
94 |
95 |
96 | 97 |
98 | 99 |
100 |

© Copyright 2022, Matias Cattaneo, Yingjie Feng, Filippo Palomba, Rocio Titiunik.

101 |
102 | 103 | Built with Sphinx using a 104 | theme 105 | provided by Read the Docs. 106 | 107 | 108 |
109 |
110 |
111 |
112 |
113 | 118 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | import os 14 | import sys 15 | sys.path.insert(0, os.path.abspath('/Users/fpalomba/Dropbox (Princeton)/projects/scpi/packages/python/scpi_pkg/src/scpi_pkg')) 16 | 17 | from scpi_pkg.scdata import scdata 18 | from scpi_pkg.scdataMulti import scdataMulti 19 | from scpi_pkg.scest import scest 20 | from scpi_pkg.scpi import scpi 21 | from scpi_pkg.scplot import scplot 22 | from scpi_pkg.scplotMulti import scplotMulti 23 | 24 | # -- Project information ----------------------------------------------------- 25 | 26 | project = 'scpi-pkg' 27 | copyright = '2022, Matias Cattaneo, Yingjie Feng, Filippo Palomba, Rocio Titiunik' 28 | author = 'Matias Cattaneo, Yingjie Feng, Filippo Palomba, Rocio Titiunik' 29 | 30 | # The full version, including alpha/beta/rc tags 31 | release = '2.2.2' 32 | 33 | 34 | # -- General configuration --------------------------------------------------- 35 | 36 | # Add any Sphinx extension module names here, as strings. They can be 37 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 38 | # ones. 39 | extensions = [ 40 | 'sphinx.ext.autosummary', 41 | 'sphinx.ext.autodoc', 42 | 'sphinx.ext.mathjax', 43 | 'sphinx.ext.viewcode', 44 | 'sphinx.ext.napoleon', 45 | 'sphinx.ext.intersphinx', 46 | 'sphinx.ext.extlinks' 47 | ] 48 | 49 | # Add any paths that contain templates here, relative to this directory. 50 | templates_path = ['_templates'] 51 | 52 | # List of patterns, relative to source directory, that match files and 53 | # directories to ignore when looking for source files. 54 | # This pattern also affects html_static_path and html_extra_path. 55 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 56 | 57 | 58 | # -- Options for HTML output ------------------------------------------------- 59 | 60 | # The theme to use for HTML and HTML Help pages. See the documentation for 61 | # a list of builtin themes. 62 | # 63 | # html_theme = 'nature' 64 | html_theme = 'sphinx_rtd_theme' 65 | 66 | # Add any paths that contain custom static files (such as style sheets) here, 67 | # relative to this directory. They are copied after the builtin static files, 68 | # so a file named "default.css" will overwrite the builtin "default.css". 69 | html_static_path = ['_static'] 70 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/index.rst: -------------------------------------------------------------------------------- 1 | .. scpi-pkg documentation master file, created by 2 | sphinx-quickstart on Tue Feb 22 10:21:54 2022. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to scpi-pkg's documentation! 7 | ==================================== 8 | The scpi package provides Python, R, and Stata implementations of estimation and inference procedures 9 | for synthetic control methods with multiple treated units and staggered adoption using least squares, 10 | lasso, ridge, or simplex-type constraints. Uncertainty is quantifed using 11 | prediction intervals as developed in `Cattaneo, Feng, and Titiunik (2021) `_ 12 | for a single treated unit and in `Cattaneo, Feng, Palomba, and Titiunik (2022b) `_ for 13 | multiple treated units and staggered adoption. 14 | 15 | Companion `R `_ and `Stata `_ packages are described in 16 | `Cattaneo, Feng, Palomba, and Titiunik (2022a) `_. 17 | 18 | Related Stata, R, and Python packages useful for inference in synthetic control methods are described 19 | in the following website: 20 | 21 | `https://nppackages.github.io/scpi/ `_ 22 | 23 | For an introduction to synthetic control methods, see `Abadie (2021) `_ and 24 | references therein. 25 | 26 | 27 | .. toctree:: 28 | :maxdepth: 2 29 | :caption: Contents: 30 | 31 | scdata 32 | scdataMulti 33 | scest 34 | scpi 35 | scplot 36 | scplotMulti 37 | Legal 38 | 39 | 40 | Indices and tables 41 | ================== 42 | 43 | * :ref:`genindex` 44 | * :ref:`modindex` 45 | * :ref:`search` 46 | 47 | 48 | References 49 | ========== 50 | Abadie, A. (2021), “Using Synthetic Controls: Feasibility, Data Requirements, and Methodological 51 | Aspects,” Journal of Economic Literature, 59, 391-425. 52 | 53 | Cattaneo, M. D., Feng, Y., and Titiunik, R. (2021), “Prediction Intervals for Synthetic Control 54 | Methods,” Journal of the American Statistical Association, 116, 1865-1880. 55 | 56 | Cattaneo, M. D., Palomba, F., Feng, Y., and Titiunik, R. (2022a), “scpi: Uncertainty Quantification for 57 | Synthetic Control Estimators”. 58 | 59 | Cattaneo, M. D., Palomba, F., Feng, Y., and Titiunik, R. (2022b), “Uncertainty Quantification in Synthetic 60 | Controls with Staggered Treatment Adoption”. -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.https://www.sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/scdata.rst: -------------------------------------------------------------------------------- 1 | Data Preparation for Synthetic Control (:py:mod:`scdata.scdata`) 2 | ======================================================================== 3 | 4 | This page describes the function ``scdata`` to prepare data for synthetic control designs. The function 5 | produces an object of class ``scdata_output`` to be passed to ``scest`` or ``scpi``. 6 | 7 | The command prepares the data to be used by scest or scpi for point estimation and inference procedures using 8 | Synthetic Control. It allows the user to specify the outcome variable, the features of the treated unit 9 | to be matched, and covariate-adjustment feature by feature. The names of the output matrices 10 | follow the notation proposed in `Cattaneo, Feng, and Titiunik (2021) `_. 11 | 12 | Syntax 13 | --------- 14 | 15 | .. currentmodule:: scpi_pkg.scdata 16 | .. autofunction:: scdata 17 | 18 | 19 | Dependencies 20 | ------------ 21 | 22 | **Python**: `cvxpy `_, 23 | 24 | `dask `_, 25 | 26 | `numpy `_, 27 | 28 | `pandas `_, 29 | 30 | `plotnine `_, 31 | 32 | `scikit-learn `_, 33 | 34 | `scipy `_, 35 | 36 | `statsmodels `_ 37 | 38 | **scpi_pkg**: none 39 | 40 | Usage 41 | ----- 42 | 43 | This example shows how to prepare the data for synthetic control methods. The raw data can be downloaded 44 | `here `_:: 45 | 46 | import pandas 47 | from scpi_pkg.scdata import scdata 48 | 49 | data = pandas.read_csv("scpi_germany.csv") 50 | 51 | id_var = 'country' 52 | outcome_var = 'gdp' 53 | time_var = 'year' 54 | features = None 55 | cov_adj = None 56 | period_pre = numpy.arange(1960, 1991) 57 | period_post = numpy.arange(1991, 2004) 58 | unit_tr = 'West Germany' 59 | unit_co = list(set(data[id_var].to_list())) 60 | unit_co = [cou for cou in unit_co if cou != 'West Germany'] 61 | constant = True 62 | report_missing = False 63 | cointegrated_data = True 64 | 65 | data_prep = scdata(df=data, id_var=id_var, time_var=time_var, 66 | outcome_var=outcome_var, period_pre=period_pre, 67 | period_post=period_post, unit_tr=unit_tr, 68 | unit_co=unit_co, features=features, cov_adj=cov_adj, 69 | cointegrated_data=cointegrated_data, constant=constant, 70 | report_missing=report_missing) 71 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/scdataMulti.rst: -------------------------------------------------------------------------------- 1 | Data Preparation for Synthetic Control with Staggered Adoption (:py:mod:`scdataMulti.scdataMulti`) 2 | ==================================================================================================== 3 | 4 | This page describes the function ``scdataMulti`` to prepare data for synthetic control designs in the general 5 | case of multiple treated units, possibly with staggered adoption. The function 6 | produces an object of class ``scdataMulti_output`` to be passed to ``scest`` or ``scpi``. 7 | 8 | The command prepares the data to be used by scest or scpi for point estimation and inference procedures using 9 | Synthetic Control. It allows the user to specify the outcome variable and, for each treated unit, the features 10 | to be matched, and covariate-adjustment feature by feature. The names of the output matrices 11 | follow the notation proposed in `Cattaneo, Feng, Palomba, and Titiunik (2022) `_. 12 | 13 | Syntax 14 | --------- 15 | 16 | .. currentmodule:: scpi_pkg.scdataMulti 17 | .. autofunction:: scdataMulti 18 | 19 | 20 | Dependencies 21 | ------------ 22 | 23 | **Python**: `cvxpy `_, 24 | 25 | `dask `_, 26 | 27 | `ecos `_, 28 | 29 | `numpy `_, 30 | 31 | `pandas `_, 32 | 33 | `plotnine `_, 34 | 35 | `scikit-learn `_, 36 | 37 | `scipy `_, 38 | 39 | `statsmodels `_ 40 | 41 | **scpi_pkg**: scdata 42 | 43 | Usage 44 | ----- 45 | Some examples regarding features and cov_adj:: 46 | 47 | # same features for all treated units 48 | features = {'anyname': [list of variables to match on]} 49 | 50 | # specify features for each treated unit 51 | features = {'treated_1': [list of variables to match on], 52 | 'treated_2': [(possibly different) list of variables to match on]} 53 | 54 | # same covariate adjustment for all treated units for all features 55 | cov_adj = {'anyname': ['constant', 'trend']} 56 | 57 | # same covariate adjustment for all treated units but feature-specific (say, three features) 58 | cov_adj = {'anyname': [['constant', 'trend'], [], ['constant']]} 59 | 60 | # different covariate adjustment for each treated unit and feature-specific (say, two features for the first unit 61 | # and three for the second treated unit) 62 | cov_adj = {'treated_1': [['constant'], [] ], 63 | 'treated_2': [['constant', 'trend'], ['trend'], []]} 64 | 65 | # unit specific presence of global constant 66 | constant = {'treated_1': True, 'treated_2': False} 67 | 68 | # unit specific presence of cointegration 69 | cointegrated_data = {'treated_1': True, 'treated_2': False} 70 | 71 | # unit specific presence of anticipation effects 72 | anticipation = {'treated_1': 0, 'treated_2': 1} 73 | 74 | aux = scdataMulti(df=df, 75 | id_var='country', 76 | treatment_var='treatment', 77 | outcome_var='gdp', 78 | time_var='year', 79 | features=features, 80 | constant=constant, 81 | anticipation=anticipation, 82 | cointegrated_data=cointegrated_data) 83 | 84 | This example shows how to prepare the data for synthetic control methods. The raw data can be downloaded 85 | `here `_:: 86 | 87 | import pandas 88 | from scdataMulti import scdataMulti 89 | 90 | df = pandas.read_csv("scpi_germany.csv") 91 | 92 | # Create a second placebo treated unit 93 | df.loc[(df['country'] == "Italy") & (df['year'] >= 1992), 'status'] = 1 94 | 95 | aux = scdataMulti(df=df, 96 | id_var='country', 97 | treatment_var='treatment', 98 | outcome_var='gdp', 99 | time_var='year') -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/scest.rst: -------------------------------------------------------------------------------- 1 | Point estimation for Synthetic Control (:py:mod:`scest.scest`) 2 | ======================================================================== 3 | 4 | This page describes the function ``scest`` to implement point estimation for synthetic control methods 5 | using least squares, lasso, ridge, or simplex-type constraints. 6 | For further information see `Cattaneo, Feng, and Titiunik (2021) `_. 7 | The names of the output matrices follow the notation proposed in `Cattaneo, Feng, Palomba, and Titiunik (2022) `_ 8 | 9 | Syntax 10 | --------- 11 | 12 | .. currentmodule:: scpi_pkg.scest 13 | .. autofunction:: scest 14 | 15 | 16 | Dependencies 17 | ------------ 18 | 19 | **Python**: `cvxpy `_, 20 | 21 | `dask `_, 22 | 23 | `ecos `_, 24 | 25 | `numpy `_, 26 | 27 | `pandas `_, 28 | 29 | `plotnine `_, 30 | 31 | `scikit-learn `_, 32 | 33 | `scipy `_, 34 | 35 | `statsmodels `_ 36 | 37 | **scpi_pkg**: scplot 38 | 39 | Usage 40 | ----- 41 | 42 | This example shows how to prepare the data and conduct estimation for synthetic control methods. The raw data can be downloaded 43 | `here `_:: 44 | 45 | import pandas 46 | from scpi_pkg.scdata import scdata 47 | from scpi_pkg.scest import scest 48 | 49 | data = pandas.read_csv("scpi_germany.csv") 50 | 51 | id_var = 'country' 52 | outcome_var = 'gdp' 53 | time_var = 'year' 54 | features = None 55 | cov_adj = None 56 | period_pre = numpy.arange(1960, 1991) 57 | period_post = numpy.arange(1991, 2004) 58 | unit_tr = 'West Germany' 59 | unit_co = list(set(data[id_var].to_list())) 60 | unit_co = [cou for cou in unit_co if cou != 'West Germany'] 61 | constant = True 62 | report_missing = False 63 | cointegrated_data = True 64 | 65 | data_prep = scdata(df=data, id_var=id_var, time_var=time_var, 66 | outcome_var=outcome_var, period_pre=period_pre, 67 | period_post=period_post, unit_tr=unit_tr, 68 | unit_co=unit_co, features=features, cov_adj=cov_adj, 69 | cointegrated_data=cointegrated_data, constant=constant, 70 | report_missing=report_missing) 71 | 72 | # SC - point estimation with simplex 73 | est_si = scest(data_prep, w_constr={'name': "simplex"}) 74 | print(est_si) 75 | est_si2 = scest(data_prep, w_constr={'p': 'L1', 'dir': '==', 'Q': 1, 'lb': 0}) 76 | print(est_si2) 77 | 78 | # SC - point estimation with lasso 79 | est_lasso = scest(data_prep, w_constr={'name': "lasso"}) 80 | print(est_lasso) 81 | est_lasso2 = scest(data_prep, w_constr={'p': 'L1', 'dir': '<=', 'Q': 1, 'lb': -numpy.inf}) 82 | print(est_lasso2) 83 | 84 | est_ridge = scest(data_prep, w_constr={'name': "ridge"}) 85 | print(est_ridge) 86 | Q_est = est_ridge.w_constr['Q'] 87 | est_ridge2 = scest(data_prep, w_constr={'p': 'L2', 'dir': '<=', 'Q': Q_est, 'lb': -numpy.inf}) 88 | print(est_ridge2) 89 | 90 | # SC - point estimation with ols 91 | est_ls = scest(data_prep, w_constr={'name': "ols"}) 92 | print(est_ls) 93 | est_ls2 = scest(data_prep, w_constr={'p': 'no norm', 'dir': None, 'Q': None, 'lb': -numpy.inf}) 94 | print(est_ls2) 95 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/scpi.rst: -------------------------------------------------------------------------------- 1 | Prediction Intervals for Synthetic Control (:py:mod:`scpi.scpi`) 2 | ======================================================================== 3 | 4 | This page describes the function ``scpi`` to implement point estimation and inference procedures for synthetic control methods 5 | using least squares, lasso, ridge, or simplex-type constraints. Uncertainty is quantified using prediction intervals according to 6 | `Cattaneo, Feng, and Titiunik (2021) `_. 7 | The names of the output matrices follow the notation proposed in `Cattaneo, Feng, Palomba, and Titiunik (2022) `_ 8 | 9 | Functions 10 | --------- 11 | 12 | .. currentmodule:: scpi_pkg.scpi 13 | .. autofunction:: scpi 14 | 15 | 16 | Dependencies 17 | ------------ 18 | 19 | **Python**: `cvxpy `_, 20 | 21 | `dask `_, 22 | 23 | `ecos `_, 24 | 25 | `numpy `_, 26 | 27 | `pandas `_, 28 | 29 | `plotnine `_, 30 | 31 | `scikit-learn `_, 32 | 33 | `scipy `_, 34 | 35 | `statsmodels `_ 36 | 37 | **scpi_pkg**: scest, scplot 38 | 39 | Usage 40 | ----- 41 | 42 | This example shows how to prepare the data and estimate prediction intervals for synthetic control methods. The raw data can be downloaded 43 | `here `_:: 44 | 45 | import pandas 46 | from scpi_pkg.scdata import scdata 47 | from scpi_pkg.scpi import scpi 48 | 49 | data = pandas.read_csv("scpi_germany.csv") 50 | 51 | id_var = 'country' 52 | outcome_var = 'gdp' 53 | time_var = 'year' 54 | features = None 55 | cov_adj = None 56 | period_pre = numpy.arange(1960, 1991) 57 | period_post = numpy.arange(1991, 2004) 58 | unit_tr = 'West Germany' 59 | unit_co = list(set(data[id_var].to_list())) 60 | unit_co = [cou for cou in unit_co if cou != 'West Germany'] 61 | constant = True 62 | report_missing = False 63 | cointegrated_data = True 64 | 65 | data_prep = scdata(df=data, id_var=id_var, time_var=time_var, 66 | outcome_var=outcome_var, period_pre=period_pre, 67 | period_post=period_post, unit_tr=unit_tr, 68 | unit_co=unit_co, features=features, cov_adj=cov_adj, 69 | cointegrated_data=cointegrated_data, constant=constant, 70 | report_missing=report_missing) 71 | 72 | # Set options for inference 73 | w_constr = {'name': 'simplex', 'Q': 1} 74 | u_missp = True 75 | u_sigma = "HC1" 76 | u_order = 1 77 | u_lags = 0 78 | e_method = "qreg" 79 | e_order = 1 80 | e_lags = 0 81 | e_alpha = 0.05 82 | u_alpha = 0.05 83 | sims = 500 84 | cores = 1 85 | 86 | pi_si = scpi(data_prep, sims=sims, w_constr=w_constr, u_order=u_order, u_lags=u_lags, 87 | e_order=e_order, e_lags=e_lags, e_method=e_method, u_missp=u_missp, 88 | u_sigma=u_sigma, cores=cores, e_alpha=e_alpha, u_alpha=u_alpha) 89 | print(pi_si) -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/scplot.rst: -------------------------------------------------------------------------------- 1 | Plots for Synthetic Control (:py:mod:`scplot.scplot`) 2 | ======================================================================== 3 | 4 | This page describes the function ``scplot`` to implement several Synthetic Control plots. 5 | The function is designed to be called after ``scest`` or ``scpi`` 6 | which implement estimation and inference procedures for Synthetic Control methods using least squares, lasso, 7 | ridge, or simplex-type constraints according to 8 | `Cattaneo, Feng, and Titiunik (2021) `_ 9 | and `Cattaneo, Feng, Palomba, and Titiunik (2022) `_ 10 | 11 | Syntax 12 | --------- 13 | 14 | .. currentmodule:: scpi_pkg.scplot 15 | .. autofunction:: scplot 16 | 17 | 18 | Dependencies 19 | ------------ 20 | 21 | **Python**: `cvxpy `_, 22 | 23 | `dask `_, 24 | 25 | `ecos `_, 26 | 27 | `numpy `_, 28 | 29 | `pandas `_, 30 | 31 | `plotnine `_, 32 | 33 | `scikit-learn `_, 34 | 35 | `scipy `_, 36 | 37 | `statsmodels `_ 38 | 39 | **scpi_pkg**: none 40 | 41 | Usage 42 | ----- 43 | 44 | This example shows how to prepare the data and conduct estimation for synthetic control methods. The raw data can be downloaded 45 | `here `_:: 46 | 47 | import pandas 48 | from scpi_pkg.scdata import scdata 49 | from scpi_pkg.scest import scest 50 | from scpi_pkg.scplot import scplot 51 | 52 | data = pandas.read_csv("scpi_germany.csv") 53 | 54 | id_var = 'country' 55 | outcome_var = 'gdp' 56 | time_var = 'year' 57 | features = None 58 | cov_adj = None 59 | period_pre = numpy.arange(1960, 1991) 60 | period_post = numpy.arange(1991, 2004) 61 | unit_tr = 'West Germany' 62 | unit_co = list(set(data[id_var].to_list())) 63 | unit_co = [cou for cou in unit_co if cou != 'West Germany'] 64 | constant = True 65 | report_missing = False 66 | cointegrated_data = True 67 | 68 | data_prep = scdata(df=data, id_var=id_var, time_var=time_var, 69 | outcome_var=outcome_var, period_pre=period_pre, 70 | period_post=period_post, unit_tr=unit_tr, 71 | unit_co=unit_co, features=features, cov_adj=cov_adj, 72 | cointegrated_data=cointegrated_data, constant=constant, 73 | report_missing=report_missing) 74 | 75 | # SC - point estimation with simplex 76 | est_si = scest(data_prep, w_constr={'name': "simplex"}) 77 | print(est_si) 78 | 79 | plot = scplot(est_si) 80 | -------------------------------------------------------------------------------- /Python/scpi_pkg/docs/scplotMulti.rst: -------------------------------------------------------------------------------- 1 | Plots for Synthetic Control with Multiple Treated Units (:py:mod:`scplotMulti.scplotMulti`) 2 | =============================================================================================== 3 | 4 | This page describes the function ``scplotMulti`` to implement several Synthetic Control plots when Multiple 5 | treated units and staggered adoption are features of the design. 6 | The function is designed to be called after ``scest`` or ``scpi`` 7 | which implement estimation and inference procedures for Synthetic Control methods using least squares, lasso, 8 | ridge, or simplex-type constraints according to 9 | `Cattaneo, Feng, and Titiunik (2021) `_ 10 | and `Cattaneo, Feng, Palomba, and Titiunik (2022) `_ 11 | 12 | Syntax 13 | --------- 14 | 15 | .. currentmodule:: scpi_pkg.scplotMulti 16 | .. autofunction:: scplotMulti 17 | 18 | 19 | Dependencies 20 | ------------ 21 | 22 | **Python**: `cvxpy `_, 23 | 24 | `dask `_, 25 | 26 | `ecos `_, 27 | 28 | `numpy `_, 29 | 30 | `pandas `_, 31 | 32 | `plotnine `_, 33 | 34 | `scikit-learn `_, 35 | 36 | `scipy `_, 37 | 38 | `statsmodels `_ 39 | 40 | **scpi_pkg**: none 41 | 42 | Usage 43 | ----- 44 | 45 | This example shows how to prepare the data and conduct estimation for synthetic control methods. The raw data can be downloaded 46 | `here `_:: 47 | 48 | import pandas 49 | from scdataMulti import scdataMulti 50 | from scest import scest 51 | from scplotMulti import scplotMulti 52 | 53 | df = pandas.read_csv("scpi_germany.csv") 54 | 55 | # Create a second placebo treated unit 56 | df.loc[(df['country'] == "Italy") & (df['year'] >= 1992), 'status'] = 1 57 | 58 | # same features for all treated units 59 | features = {'anyname': [list of variables to match on]} 60 | 61 | # same covariate adjustment for all treated units for all features 62 | cov_adj = {'anyname': ['constant', 'trend']} 63 | 64 | # unit specific presence of global constant 65 | constant = {'treated_1': True, 'treated_2': False} 66 | 67 | # unit specific presence of cointegration 68 | cointegrated_data = {'treated_1': True, 'treated_2': False} 69 | 70 | # unit specific presence of anticipation effects 71 | anticipation = {'treated_1': 0, 'treated_2': 1} 72 | 73 | aux = scdataMulti(df=df, 74 | id_var='country', 75 | treatment_var='treatment', 76 | outcome_var='gdp', 77 | time_var='year', 78 | features=features, 79 | constant=constant, 80 | anticipation=anticipation, 81 | cointegrated_data=cointegrated_data) 82 | 83 | res = scest(aux) 84 | 85 | scplotMulti(res) 86 | -------------------------------------------------------------------------------- /Python/scpi_pkg/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "setuptools>=46.4.0", 4 | "wheel" 5 | ] 6 | build-backend = "setuptools.build_meta" -------------------------------------------------------------------------------- /Python/scpi_pkg/setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = scpi_pkg 3 | version = attr: scpi_pkg.version.__version__ 4 | author = Filippo Palomba 5 | author_email = fpalomba@princeton.edu 6 | description = The package computes point estimates and prediction intervals for Synthetic Control methods with multiple treated units and staggered adoption as proposed in Cattaneo, Feng, Palomba, and Titiunik (2024). 7 | long_description = file: README.md 8 | long_description_content_type = text/markdown 9 | url = https://nppackages.github.io/scpi/ 10 | project_urls = 11 | Bug Tracker = https://nppackages.github.io/scpi/ 12 | classifiers = 13 | Programming Language :: Python :: 3 14 | License :: OSI Approved :: MIT License 15 | Operating System :: OS Independent 16 | 17 | [options] 18 | package_dir = 19 | = src 20 | packages = find: 21 | python_requires = >=3.7 22 | install_requires = 23 | cvxpy >= 1.1.18 24 | dask >= 2021.04.0 25 | ecos >= 2.0.7 26 | luddite >= 1.0.2 27 | mizani >= 0.8.1 28 | numpy >= 1.20.1 29 | pandas >= 1.5.0 30 | plotnine >= 0.8.0 31 | scikit-learn >= 0.24.1 32 | scipy >= 1.7.1 33 | statsmodels >= 0.12.2 34 | 35 | [options.packages.find] 36 | where = src 37 | -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.2 2 | Name: scpi_pkg 3 | Version: 3.0.0 4 | Summary: The package computes point estimates and prediction intervals for Synthetic Control methods with multiple treated units and staggered adoption as proposed in Cattaneo, Feng, Palomba, and Titiunik (2024). 5 | Home-page: https://nppackages.github.io/scpi/ 6 | Author: Filippo Palomba 7 | Author-email: fpalomba@princeton.edu 8 | Project-URL: Bug Tracker, https://nppackages.github.io/scpi/ 9 | Classifier: Programming Language :: Python :: 3 10 | Classifier: License :: OSI Approved :: MIT License 11 | Classifier: Operating System :: OS Independent 12 | Requires-Python: >=3.7 13 | Description-Content-Type: text/markdown 14 | License-File: LICENSE 15 | Requires-Dist: cvxpy>=1.1.18 16 | Requires-Dist: dask>=2021.04.0 17 | Requires-Dist: ecos>=2.0.7 18 | Requires-Dist: luddite>=1.0.2 19 | Requires-Dist: mizani>=0.8.1 20 | Requires-Dist: numpy>=1.20.1 21 | Requires-Dist: pandas>=1.5.0 22 | Requires-Dist: plotnine>=0.8.0 23 | Requires-Dist: scikit-learn>=0.24.1 24 | Requires-Dist: scipy>=1.7.1 25 | Requires-Dist: statsmodels>=0.12.2 26 | 27 | # SCPI_PKG 28 | 29 | The `scpi_pkg` package provides Python implementations of estimation and inference procedures for Synthetic Control methods. 30 | 31 | ## Authors 32 | 33 | Matias D. Cattaneo () 34 | 35 | Yingjie Feng () 36 | 37 | Filippo Palomba () 38 | 39 | Rocio Titiunik () 40 | 41 | ## Website 42 | 43 | https://nppackages.github.io/scpi/ 44 | 45 | ## Installation 46 | 47 | To install/update use pip 48 | 49 | ``` 50 | pip install scpi_pkg 51 | ``` 52 | 53 | # Usage 54 | 55 | ``` 56 | from from scpi_pkg.scdata import scdata 57 | from from scpi_pkg.scdataMulti import scdataMulti 58 | from scpi_pkg.scest import scest 59 | from scpi_pkg.scpi import scpi 60 | from scpi_pkg.scplot import scplot 61 | from scpi_pkg.scplotMulti import scplotMulti 62 | ``` 63 | 64 | - Replication: [Germany reunification example](https://github.com/nppackages/scpi/blob/main/Python/scpi_illustration.py). 65 | 66 | ## Dependencies 67 | 68 | - cvxpy (>= 1.1.18) 69 | - dask (>= 2021.04.0) 70 | - ecos (>= 2.0.7) 71 | - luddite (>= 1.0.2) 72 | - numpy (>= 1.20.1) 73 | - pandas (>= 1.5.0) 74 | - plotnine (>= 0.8.0) 75 | - scikit-learn (>= 0.24.1) 76 | - scipy (>= 1.7.1) 77 | - statsmodels (>= 0.12.2) 78 | 79 | ## References 80 | 81 | For overviews and introductions, see [nppackages website](https://nppackages.github.io/). 82 | 83 | ### Software and Implementation 84 | 85 | - Cattaneo, Feng, Palomba, and Titiunik (2024+) [scpi: Uncertainty Quantification for Synthetic Control Estimators](https://arxiv.org/abs/2202.05984). forthcoming at *Journal of Statistical Software.* 86 | 87 | ### Technical and Methodological 88 | 89 | - Cattaneo, Feng, and Titiunik (2021): [Prediction Intervals for Synthetic Control Methods](https://cattaneo.princeton.edu/papers/Cattaneo-Feng-Titiunik_2021_JASA.pdf). 90 | _Journal of the American Statistical Association_. 91 | - Cattaneo, Feng, Palomba, and Titiunik (2023): [Uncertainty Quantification in Synthetic Controls with Staggered Treatment Adoption](https://arxiv.org/abs/2210.05026), working paper. 92 | -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | LICENSE 2 | README.md 3 | pyproject.toml 4 | setup.cfg 5 | src/scpi_pkg/__init__.py 6 | src/scpi_pkg/funs.py 7 | src/scpi_pkg/scdata.py 8 | src/scpi_pkg/scdataMulti.py 9 | src/scpi_pkg/scest.py 10 | src/scpi_pkg/scpi.py 11 | src/scpi_pkg/scplot.py 12 | src/scpi_pkg/scplotMulti.py 13 | src/scpi_pkg/version.py 14 | src/scpi_pkg.egg-info/PKG-INFO 15 | src/scpi_pkg.egg-info/SOURCES.txt 16 | src/scpi_pkg.egg-info/dependency_links.txt 17 | src/scpi_pkg.egg-info/requires.txt 18 | src/scpi_pkg.egg-info/top_level.txt -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg.egg-info/requires.txt: -------------------------------------------------------------------------------- 1 | cvxpy>=1.1.18 2 | dask>=2021.04.0 3 | ecos>=2.0.7 4 | luddite>=1.0.2 5 | mizani>=0.8.1 6 | numpy>=1.20.1 7 | pandas>=1.5.0 8 | plotnine>=0.8.0 9 | scikit-learn>=0.24.1 10 | scipy>=1.7.1 11 | statsmodels>=0.12.2 12 | -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | scpi_pkg 2 | -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__init__.py -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/funs.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/funs.cpython-38.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/funs.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/funs.cpython-39.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scdata.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scdata.cpython-310.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scdata.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scdata.cpython-38.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scdata.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scdata.cpython-39.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scdataMulti.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scdataMulti.cpython-310.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scdataMulti.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scdataMulti.cpython-38.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scdataMulti.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scdataMulti.cpython-39.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scest.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scest.cpython-310.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scest.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scest.cpython-38.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scest.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scest.cpython-39.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scpi.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scpi.cpython-310.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scpi.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scpi.cpython-38.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scpi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scpi.cpython-39.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scplot.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scplot.cpython-310.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scplot.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scplot.cpython-38.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scplot.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scplot.cpython-39.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scplotMulti.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scplotMulti.cpython-310.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scplotMulti.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scplotMulti.cpython-38.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/scplotMulti.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/scplotMulti.cpython-39.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/__pycache__/support.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/Python/scpi_pkg/src/scpi_pkg/__pycache__/support.cpython-38.pyc -------------------------------------------------------------------------------- /Python/scpi_pkg/src/scpi_pkg/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '3.0.0' 2 | -------------------------------------------------------------------------------- /R/scpi.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/R/scpi.pdf -------------------------------------------------------------------------------- /R/scpi/.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /R/scpi/.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macOS-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 24 | - {os: ubuntu-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'oldrel-1'} 26 | 27 | env: 28 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 29 | R_KEEP_PKG_SOURCE: yes 30 | 31 | steps: 32 | - uses: actions/checkout@v2 33 | 34 | - uses: r-lib/actions/setup-pandoc@v2 35 | 36 | - uses: r-lib/actions/setup-r@v2 37 | with: 38 | r-version: ${{ matrix.config.r }} 39 | http-user-agent: ${{ matrix.config.http-user-agent }} 40 | use-public-rspm: true 41 | 42 | - uses: r-lib/actions/setup-r-dependencies@v2 43 | with: 44 | extra-packages: any::rcmdcheck 45 | needs: check 46 | 47 | - uses: r-lib/actions/check-r-package@v2 48 | with: 49 | upload-snapshots: true 50 | -------------------------------------------------------------------------------- /R/scpi/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: scpi 2 | Title: Prediction Intervals for Synthetic Control Methods with Multiple Treated Units and Staggered Adoption 3 | Version: 3.0.0 4 | Authors@R: 5 | c(person(given = "Matias", 6 | family = "Cattaneo", 7 | role = "aut"), 8 | person(given = "Yingjie", 9 | family = "Feng", 10 | role = "aut"), 11 | person(given = "Filippo", 12 | family = "Palomba", 13 | role = c("aut","cre"), 14 | email = "fpalomba@princeton.edu"), 15 | person(given = "Rocio", 16 | family = "Titiunik", 17 | role = "aut")) 18 | URL: https://nppackages.github.io/scpi/ 19 | Description: Implementation of prediction and inference procedures for Synthetic Control methods using least square, lasso, ridge, or simplex-type constraints. Uncertainty is quantified with prediction intervals as developed in Cattaneo, Feng, and Titiunik (2021) for a single treated unit and in Cattaneo, Feng, Palomba, and Titiunik (2023) for multiple treated units and staggered adoption. More details about the software implementation can be found in Cattaneo, Feng, Palomba, and Titiunik (2024) . 20 | Depends: R (>= 4.1.0) 21 | License: GPL-2 22 | Encoding: UTF-8 23 | Imports: abind (>= 1.4.5), 24 | CVXR (>= 1.0-10), 25 | doSNOW (>= 1.0.19), 26 | dplyr (>= 1.0.7), 27 | ECOSolveR (>= 0.5.4), 28 | fastDummies (>= 1.6.3), 29 | foreach (>= 1.5.1), 30 | ggplot2 (>= 3.3.3), 31 | magrittr (>= 2.0.1), 32 | MASS (>= 7.3), 33 | Matrix (>= 1.3.3), 34 | methods (>= 4.1.0), 35 | parallel (>= 4.1.0), 36 | purrr (>= 0.3.4), 37 | Qtools (>= 1.5.6), 38 | reshape2 (>= 1.4.4), 39 | rlang (>= 0.4.11), 40 | stats (>= 4.1.0), 41 | stringr (>= 1.4.0), 42 | tibble (>= 3.1.2), 43 | tidyr (>= 1.1.3), 44 | utils (>= 4.1.1) 45 | LazyData: true 46 | Roxygen: list(markdown = TRUE) 47 | RoxygenNote: 7.3.1 48 | Suggests: 49 | testthat (>= 3.0.0) 50 | Config/testthat/edition: 3 51 | -------------------------------------------------------------------------------- /R/scpi/NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(coef,scest) 4 | S3method(coef,scpi) 5 | S3method(print,scdata) 6 | S3method(print,scdataMulti) 7 | S3method(print,scest) 8 | S3method(print,scpi) 9 | S3method(summary,scdata) 10 | S3method(summary,scdataMulti) 11 | S3method(summary,scest) 12 | S3method(summary,scpi) 13 | export(scdata) 14 | export(scdataMulti) 15 | export(scest) 16 | export(scpi) 17 | export(scplot) 18 | export(scplotMulti) 19 | import(CVXR) 20 | import(ECOSolveR) 21 | import(abind) 22 | import(doSNOW) 23 | import(foreach) 24 | import(ggplot2) 25 | import(parallel) 26 | import(rlang, except = c(is_vector,is_complex)) 27 | 28 | import(stats, except = c(lag,filter,power)) 29 | import(tidyr) 30 | importFrom(MASS,ginv) 31 | importFrom(Matrix,bdiag) 32 | importFrom(Qtools,rrq) 33 | importFrom(dplyr,lag) 34 | importFrom(dplyr,left_join) 35 | importFrom(fastDummies,dummy_cols) 36 | importFrom(magrittr,"%>%") 37 | importFrom(methods,as) 38 | importFrom(methods,is) 39 | importFrom(purrr,map) 40 | importFrom(reshape2,melt) 41 | importFrom(stringr,str_remove) 42 | importFrom(stringr,str_split) 43 | importFrom(tibble,is_tibble) 44 | importFrom(utils,flush.console) 45 | -------------------------------------------------------------------------------- /R/scpi/R/data.R: -------------------------------------------------------------------------------- 1 | #' Replication Dataset for Estimating the Economic Impact of German Reunification 2 | #' 3 | #' A dataset containing some economic indicators of 17 OECD countries from 1960 4 | #' to 2003. 5 | #' 6 | #' @format A data frame with 748 rows and 11 variables: 7 | #' \describe{ 8 | #' \item{index}{country index.} 9 | #' \item{country}{name of the country.} 10 | #' \item{year}{time index, in years.} 11 | #' \item{gdp}{GDP per Capita (PPP, 2002 USD).} 12 | #' \item{infrate}{annual percentage change in consumer prices (base year 1995).} 13 | #' \item{trade}{trade openness measured as export plus imports as percentage of GDP.} 14 | #' \item{schooling}{percentage of secondary school attained in the total population aged 25 and older.} 15 | #' \item{industry}{industry share of value added.} 16 | #' } 17 | #' @source \url{https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/24714} 18 | "scpi_germany" -------------------------------------------------------------------------------- /R/scpi/R/scdataMulti_methods.R: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | #' Summary Method for Synthetic Control 3 | #' 4 | #' @description The print method for synthetic control data objects. 5 | #' 6 | #' @param x Class "scdataMulti" object, obtained by calling \code{\link{scdataMulti}}. 7 | #' @param ... Other arguments. 8 | #' 9 | #' @return No return value, called to print \code{\link{scdataMulti}} results. 10 | #' 11 | #' @author 12 | #' Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 13 | #' 14 | #' Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 15 | #' 16 | #' Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 17 | #' 18 | #' Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 19 | #' 20 | #' @seealso \code{\link{scdataMulti}} for synthetic control data preparation. 21 | #' 22 | #' Supported methods: \code{\link{print.scdataMulti}}, \code{\link{summary.scdataMulti}}. 23 | #' 24 | #' 25 | #' @export 26 | #' 27 | 28 | print.scdataMulti <- function(x, ...) { 29 | trunits <- length(x$specs$treated.units) 30 | cat(paste0("Prepared Data for ", trunits, " treated units.\n")) 31 | } 32 | 33 | ################################################################################ 34 | #' Summary Method for Synthetic Control Prediction 35 | #' 36 | #' @description The summary method for synthetic control prediction objects. 37 | #' 38 | #' @param object Class "scdataMulti" object, obtained by calling \code{\link{scdataMulti}}. 39 | #' @param ... Additional arguments 40 | #' 41 | #' @return No return value, called to summarize \code{\link{scdataMulti}} results. 42 | #' 43 | #' @author 44 | #' Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 45 | #' 46 | #' Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 47 | #' 48 | #' Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 49 | #' 50 | #' Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 51 | #' 52 | #' @seealso \code{\link{scdataMulti}} 53 | #' 54 | #' Supported methods: \code{\link{print.scdataMulti}}, \code{\link{summary.scdataMulti}}. 55 | #' 56 | #' @export 57 | 58 | summary.scdataMulti <- function(object, ...) { 59 | trunits <- object$specs$treated.units 60 | 61 | for (tr in trunits) { 62 | J <- object$specs$J[[tr]] 63 | M <- object$specs$M[[tr]] 64 | K <- object$specs$K[[tr]] 65 | KM <- object$specs$KM[[tr]] 66 | T0 <- object$specs$T0.features[[tr]] 67 | 68 | pt.in <- object$specs$period.pre[[tr]][1] 69 | pt.fi <- object$specs$period.pre[[tr]][length(object$specs$period.pre[[tr]])] 70 | 71 | pot.in <- object$specs$period.post[[tr]][1] 72 | pot.fi <- object$specs$period.post[[tr]][length(object$specs$period.post[[tr]])] 73 | 74 | cat("--------------------------------------------------------------------\n") 75 | cat(paste0("Synthetic Control - Setup for ", tr, " \n")) 76 | cat("\n") 77 | 78 | cat(paste("Treated Unit: ", tr , "\n", sep = "")) 79 | cat(paste("Size of the donor pool: ", J, "\n", sep = "")) 80 | cat(paste("Features: ", M, "\n", sep = "")) 81 | cat(paste("Pre-treatment period: ", pt.in, " || ", pt.fi, "\n", sep = "")) 82 | cat(paste("Post-treatment period: ", pot.in, " || ", pot.fi, "\n", sep = "")) 83 | 84 | if (M == 1) { 85 | cat(paste("Pre-treatment periods used in estimation: ", T0, "\n", sep = "")) 86 | cat(paste("Covariates used for adjustment: ", KM, "\n", sep = "")) 87 | 88 | } else { 89 | cat("Pre-treatment periods used in estimation per feature:\n") 90 | print(T0) 91 | cat("Covariates used for adjustment per feature:\n") 92 | print(K) 93 | } 94 | cat("\n") 95 | } 96 | cat("--------------------------------------------------------------------\n") 97 | 98 | } 99 | -------------------------------------------------------------------------------- /R/scpi/R/scdata_methods.R: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | #' Summary Method for Synthetic Control 3 | #' 4 | #' @description The print method for synthetic control data objects. 5 | #' 6 | #' @param x Class "scdata" object, obtained by calling \code{\link{scdata}}. 7 | #' @param ... Other arguments. 8 | #' 9 | #' @return No return value, called to print \code{\link{scdata}} results. 10 | #' 11 | #' @author 12 | #' Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 13 | #' 14 | #' Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 15 | #' 16 | #' Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 17 | #' 18 | #' Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 19 | #' 20 | #' @seealso \code{\link{scdata}} for synthetic control data preparation. 21 | #' 22 | #' Supported methods: \code{\link{print.scdata}}, \code{\link{summary.scdata}}. 23 | #' 24 | #' @export 25 | #' 26 | #' 27 | 28 | print.scdata <- function(x, ...) { 29 | tr.unit <- colnames(x$A) 30 | cat(paste0("Prepared Data for ", tr.unit, ".\n")) 31 | } 32 | 33 | ################################################################################ 34 | #' Summary Method for Synthetic Control Prediction 35 | #' 36 | #' @description The summary method for synthetic control prediction objects. 37 | #' 38 | #' @param object Class "scest" object, obtained by calling \code{\link{scdata}}. 39 | #' @param ... Additional arguments 40 | #' 41 | #' @return No return value, called to summarize \code{\link{scdata}} results. 42 | #' 43 | #' @author 44 | #' Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 45 | #' 46 | #' Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 47 | #' 48 | #' Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 49 | #' 50 | #' Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 51 | #' 52 | #' @seealso \code{\link{scdata}} 53 | #' 54 | #' Supported methods: \code{\link{print.scdata}}, \code{\link{summary.scdata}}. 55 | #' 56 | #' @export 57 | 58 | summary.scdata <- function(object, ...) { 59 | 60 | J <- object$specs$J 61 | M <- object$specs$M 62 | K <- object$specs$K 63 | KM <- object$specs$KM 64 | T0 <- object$specs$T0.features 65 | tr.unit <- colnames(object$A) 66 | pt.in <- strsplit(rownames(object$Y.pre)[1], "\\.")[[1]][2] 67 | pt.fi <- strsplit(rownames(object$Y.pre)[length(object$Y.pre)], "\\.")[[1]][2] 68 | pot.in <- strsplit(rownames(object$Y.post)[1], "\\.")[[1]][2] 69 | pot.fi <- strsplit(rownames(object$Y.post)[length(object$Y.post)], "\\.")[[1]][2] 70 | 71 | cat("\n") 72 | cat(paste0("Synthetic Control - Setup\n")) 73 | cat("\n") 74 | 75 | cat(paste("Treated Unit: ", tr.unit, "\n", sep = "")) 76 | cat(paste("Size of the donor pool: ", J, "\n", sep = "")) 77 | cat(paste("Features: ", M, "\n", sep = "")) 78 | cat(paste("Pre-treatment period: ", pt.in, " || ", pt.fi, "\n", sep = "")) 79 | cat(paste("Post-treatment period: ", pot.in, " || ", pot.fi, "\n", sep = "")) 80 | 81 | if (M == 1) { 82 | cat(paste("Pre-treatment periods used in estimation: ", T0, "\n", sep = "")) 83 | cat(paste("Covariates used for adjustment: ", KM, "\n", sep = "")) 84 | 85 | } else { 86 | cat("Pre-treatment periods used in estimation per feature:\n") 87 | print(T0) 88 | cat("Covariates used for adjustment per feature:\n") 89 | print(K) 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /R/scpi/R/scpi-package.R: -------------------------------------------------------------------------------- 1 | #' @title \code{scpi}: A Package to Compute Synthetic Control Prediction Intervals With Multiple Treated Units and Staggered Adoption 2 | #' 3 | #' @description The package implements estimation, inference procedures, and produces plots for Synthetic Control (SC) methods 4 | #' using least squares, lasso, ridge, or simplex-type 5 | #' constraints. Uncertainty is quantified using prediction intervals according to 6 | #' \href{https://nppackages.github.io/references/Cattaneo-Feng-Titiunik_2021_JASA.pdf}{Cattaneo, Feng, and Titiunik (2021)}. 7 | #' 8 | #' Included functions are: \link{scdata} and \link{scdataMulti} for data preparation, \link{scest} for point estimation, 9 | #' \link{scpi} for inference procedures, and \link{scplot} and \link{scplotMulti} for plots. 10 | #' 11 | #' \code{print()} and \code{summary()} methods are available for \code{\link{scest}} and \code{\link{scpi}}. 12 | #' 13 | #' Companion \href{https://www.stata.com/}{Stata} and \href{https://www.python.org/}{Python} packages are described in 14 | #' \href{https://arxiv.org/abs/2202.05984}{Cattaneo, Feng, Palomba, and Titiunik (2022)}. 15 | #' 16 | #' Related Stata, R, and Python packages useful for inference in SC designs are described in the following website: 17 | #' 18 | #' \href{ https://nppackages.github.io/scpi/}{ https://nppackages.github.io/scpi/} 19 | #' 20 | #' For an introduction to synthetic control methods, see \href{https://www.aeaweb.org/articles?id=10.1257/jel.20191450}{Abadie (2021)} and references therein. 21 | #' 22 | #' @author 23 | #' Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 24 | #' 25 | #' Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 26 | #' 27 | #' Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 28 | #' 29 | #' Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 30 | #' 31 | #' @references 32 | #' \itemize{ 33 | #' \item{\href{https://www.aeaweb.org/articles?id=10.1257/jel.20191450}{Abadie, A. (2021)}. Using synthetic controls: Feasibility, data requirements, and methodological aspects. 34 | #' \emph{Journal of Economic Literature}, 59(2), 391-425.} 35 | #' \item{\href{https://nppackages.github.io/references/Cattaneo-Feng-Titiunik_2021_JASA.pdf}{Cattaneo, M. D., Feng, Y., and Titiunik, R. 36 | #' (2021)}. Prediction intervals for synthetic control methods. \emph{Journal of the American Statistical Association}, 116(536), 1865-1880.} 37 | #' \item{\href{https://arxiv.org/abs/2202.05984}{Cattaneo, M. D., Feng, Y., Palomba F., and Titiunik, R. (2022).} 38 | #' scpi: Uncertainty Quantification for Synthetic Control Methods, \emph{arXiv}:2202.05984.} 39 | #' \item{\href{https://arxiv.org/abs/2210.05026}{Cattaneo, M. D., Feng, Y., Palomba F., and Titiunik, R. (2022).} 40 | #' Uncertainty Quantification in Synthetic Controls with Staggered Treatment Adoption, \emph{arXiv}:2210.05026.} 41 | #' } 42 | #' 43 | #' @importFrom dplyr lag 44 | #' @importFrom dplyr left_join 45 | #' @importFrom fastDummies dummy_cols 46 | #' @importFrom magrittr %>% 47 | #' @importFrom Matrix bdiag 48 | #' @importFrom MASS ginv 49 | #' @importFrom methods as 50 | #' @importFrom methods is 51 | #' @importFrom purrr map 52 | #' @importFrom reshape2 melt 53 | #' @importFrom Qtools rrq 54 | #' @importFrom stringr str_remove 55 | #' @importFrom stringr str_split 56 | #' @importFrom tibble is_tibble 57 | #' @importFrom utils flush.console 58 | #' 59 | #' @import abind 60 | #' @import CVXR 61 | #' @import doSNOW 62 | #' @import ECOSolveR 63 | #' @import foreach 64 | #' @import ggplot2 65 | #' @import parallel 66 | #' @import tidyr 67 | #' 68 | #' @rawNamespace import(stats, except = c(lag,filter,power)) 69 | #' @rawNamespace import(rlang, except = c(is_vector,is_complex)) 70 | #' 71 | #' @aliases scpi-package 72 | "_PACKAGE" 73 | 74 | ## quiets concerns of R CMD check re: the .'s that appear in pipelines 75 | if (getRversion() >= "2.15.1") utils::globalVariables(c(".")) 76 | -------------------------------------------------------------------------------- /R/scpi/data/scpi_germany.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/R/scpi/data/scpi_germany.RData -------------------------------------------------------------------------------- /R/scpi/man/coef.scest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scest_methods.R 3 | \name{coef.scest} 4 | \alias{coef.scest} 5 | \title{Coef Method for Synthetic Control Methods} 6 | \usage{ 7 | \method{coef}{scest}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{Class "scest" object, obtained by calling \code{\link{scest}}.} 11 | 12 | \item{...}{Other arguments (eg. \code{ncols}).} 13 | } 14 | \value{ 15 | No return value, called to show \code{\link{scest}} constructed weights. 16 | } 17 | \description{ 18 | The coef method for synthetic control prediction fitted objects. 19 | } 20 | \seealso{ 21 | \code{\link{scest}} for synthetic control prediction. 22 | 23 | Supported methods: \code{\link{print.scest}}, \code{\link{summary.scest}}, \code{\link{coef.scest}}. 24 | } 25 | \author{ 26 | Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 27 | 28 | Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 29 | 30 | Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 31 | 32 | Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 33 | } 34 | -------------------------------------------------------------------------------- /R/scpi/man/coef.scpi.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scpi_methods.R 3 | \name{coef.scpi} 4 | \alias{coef.scpi} 5 | \title{Coef Method for Synthetic Control Methods} 6 | \usage{ 7 | \method{coef}{scpi}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{Class "scpi" object, obtained by calling \code{\link{scpi}}.} 11 | 12 | \item{...}{Other arguments (eg. \code{ncols}).} 13 | } 14 | \value{ 15 | No return value, called to show \code{\link{scpi}} constructed weights. 16 | } 17 | \description{ 18 | The coef method for synthetic control prediction fitted objects. 19 | } 20 | \seealso{ 21 | \code{\link{scpi}} for synthetic control prediction. 22 | 23 | Supported methods: \code{\link{print.scpi}}, \code{\link{summary.scpi}}, \code{\link{coef.scpi}}. 24 | } 25 | \author{ 26 | Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 27 | 28 | Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 29 | 30 | Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 31 | 32 | Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 33 | } 34 | -------------------------------------------------------------------------------- /R/scpi/man/print.scdata.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scdata_methods.R 3 | \name{print.scdata} 4 | \alias{print.scdata} 5 | \title{Summary Method for Synthetic Control} 6 | \usage{ 7 | \method{print}{scdata}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{Class "scdata" object, obtained by calling \code{\link{scdata}}.} 11 | 12 | \item{...}{Other arguments.} 13 | } 14 | \value{ 15 | No return value, called to print \code{\link{scdata}} results. 16 | } 17 | \description{ 18 | The print method for synthetic control data objects. 19 | } 20 | \seealso{ 21 | \code{\link{scdata}} for synthetic control data preparation. 22 | 23 | Supported methods: \code{\link{print.scdata}}, \code{\link{summary.scdata}}. 24 | } 25 | \author{ 26 | Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 27 | 28 | Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 29 | 30 | Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 31 | 32 | Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 33 | } 34 | -------------------------------------------------------------------------------- /R/scpi/man/print.scdataMulti.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scdataMulti_methods.R 3 | \name{print.scdataMulti} 4 | \alias{print.scdataMulti} 5 | \title{Summary Method for Synthetic Control} 6 | \usage{ 7 | \method{print}{scdataMulti}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{Class "scdataMulti" object, obtained by calling \code{\link{scdataMulti}}.} 11 | 12 | \item{...}{Other arguments.} 13 | } 14 | \value{ 15 | No return value, called to print \code{\link{scdataMulti}} results. 16 | } 17 | \description{ 18 | The print method for synthetic control data objects. 19 | } 20 | \seealso{ 21 | \code{\link{scdataMulti}} for synthetic control data preparation. 22 | 23 | Supported methods: \code{\link{print.scdataMulti}}, \code{\link{summary.scdataMulti}}. 24 | } 25 | \author{ 26 | Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 27 | 28 | Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 29 | 30 | Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 31 | 32 | Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 33 | } 34 | -------------------------------------------------------------------------------- /R/scpi/man/print.scest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scest_methods.R 3 | \name{print.scest} 4 | \alias{print.scest} 5 | \title{Print Method for Synthetic Control Methods} 6 | \usage{ 7 | \method{print}{scest}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{Class "scest" object, obtained by calling \code{\link{scest}}.} 11 | 12 | \item{...}{Other arguments.} 13 | } 14 | \value{ 15 | No return value, called to print \code{\link{scest}} results. 16 | } 17 | \description{ 18 | The print method for synthetic control prediction fitted objects. 19 | } 20 | \seealso{ 21 | \code{\link{scest}} for synthetic control prediction. 22 | 23 | Supported methods: \code{\link{print.scest}}, \code{\link{summary.scest}}, \code{\link{coef.scest}}. 24 | } 25 | \author{ 26 | Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 27 | 28 | Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 29 | 30 | Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 31 | 32 | Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 33 | } 34 | -------------------------------------------------------------------------------- /R/scpi/man/print.scpi.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scpi_methods.R 3 | \name{print.scpi} 4 | \alias{print.scpi} 5 | \title{Print Method for Synthetic Control Inference} 6 | \usage{ 7 | \method{print}{scpi}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{Class "scpi" object, obtained by calling \code{\link{scpi}}.} 11 | 12 | \item{...}{Other arguments.} 13 | } 14 | \value{ 15 | No return value, called to print \code{\link{scpi}} results. 16 | } 17 | \description{ 18 | The print method for synthetic control inference objects. 19 | } 20 | \seealso{ 21 | \code{\link{scpi}} for synthetic control inference 22 | 23 | Supported methods: \code{\link{print.scpi}}, \code{\link{summary.scpi}}. 24 | } 25 | \author{ 26 | Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 27 | 28 | Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 29 | 30 | Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 31 | 32 | Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 33 | } 34 | -------------------------------------------------------------------------------- /R/scpi/man/scpi-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scpi-package.R 3 | \docType{package} 4 | \name{scpi-package} 5 | \alias{scpi-package} 6 | \title{\code{scpi}: A Package to Compute Synthetic Control Prediction Intervals With Multiple Treated Units and Staggered Adoption} 7 | \description{ 8 | The package implements estimation, inference procedures, and produces plots for Synthetic Control (SC) methods 9 | using least squares, lasso, ridge, or simplex-type 10 | constraints. Uncertainty is quantified using prediction intervals according to 11 | \href{https://nppackages.github.io/references/Cattaneo-Feng-Titiunik_2021_JASA.pdf}{Cattaneo, Feng, and Titiunik (2021)}. 12 | 13 | Included functions are: \link{scdata} and \link{scdataMulti} for data preparation, \link{scest} for point estimation, 14 | \link{scpi} for inference procedures, and \link{scplot} and \link{scplotMulti} for plots. 15 | 16 | \code{print()} and \code{summary()} methods are available for \code{\link{scest}} and \code{\link{scpi}}. 17 | 18 | Companion \href{https://www.stata.com/}{Stata} and \href{https://www.python.org/}{Python} packages are described in 19 | \href{https://arxiv.org/abs/2202.05984}{Cattaneo, Feng, Palomba, and Titiunik (2022)}. 20 | 21 | Related Stata, R, and Python packages useful for inference in SC designs are described in the following website: 22 | 23 | \href{ https://nppackages.github.io/scpi/}{ https://nppackages.github.io/scpi/} 24 | 25 | For an introduction to synthetic control methods, see \href{https://www.aeaweb.org/articles?id=10.1257/jel.20191450}{Abadie (2021)} and references therein. 26 | } 27 | \references{ 28 | \itemize{ 29 | \item{\href{https://www.aeaweb.org/articles?id=10.1257/jel.20191450}{Abadie, A. (2021)}. Using synthetic controls: Feasibility, data requirements, and methodological aspects. 30 | \emph{Journal of Economic Literature}, 59(2), 391-425.} 31 | \item{\href{https://nppackages.github.io/references/Cattaneo-Feng-Titiunik_2021_JASA.pdf}{Cattaneo, M. D., Feng, Y., and Titiunik, R. 32 | (2021)}. Prediction intervals for synthetic control methods. \emph{Journal of the American Statistical Association}, 116(536), 1865-1880.} 33 | \item{\href{https://arxiv.org/abs/2202.05984}{Cattaneo, M. D., Feng, Y., Palomba F., and Titiunik, R. (2022).} 34 | scpi: Uncertainty Quantification for Synthetic Control Methods, \emph{arXiv}:2202.05984.} 35 | \item{\href{https://arxiv.org/abs/2210.05026}{Cattaneo, M. D., Feng, Y., Palomba F., and Titiunik, R. (2022).} 36 | Uncertainty Quantification in Synthetic Controls with Staggered Treatment Adoption, \emph{arXiv}:2210.05026.} 37 | } 38 | } 39 | \seealso{ 40 | Useful links: 41 | \itemize{ 42 | \item \url{https://nppackages.github.io/scpi/} 43 | } 44 | 45 | } 46 | \author{ 47 | Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 48 | 49 | Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 50 | 51 | Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 52 | 53 | Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 54 | } 55 | -------------------------------------------------------------------------------- /R/scpi/man/scpi_germany.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{scpi_germany} 5 | \alias{scpi_germany} 6 | \title{Replication Dataset for Estimating the Economic Impact of German Reunification} 7 | \format{ 8 | A data frame with 748 rows and 11 variables: 9 | \describe{ 10 | \item{index}{country index.} 11 | \item{country}{name of the country.} 12 | \item{year}{time index, in years.} 13 | \item{gdp}{GDP per Capita (PPP, 2002 USD).} 14 | \item{infrate}{annual percentage change in consumer prices (base year 1995).} 15 | \item{trade}{trade openness measured as export plus imports as percentage of GDP.} 16 | \item{schooling}{percentage of secondary school attained in the total population aged 25 and older.} 17 | \item{industry}{industry share of value added.} 18 | } 19 | } 20 | \source{ 21 | \url{https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/24714} 22 | } 23 | \usage{ 24 | scpi_germany 25 | } 26 | \description{ 27 | A dataset containing some economic indicators of 17 OECD countries from 1960 28 | to 2003. 29 | } 30 | \keyword{datasets} 31 | -------------------------------------------------------------------------------- /R/scpi/man/scplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scplot.R 3 | \name{scplot} 4 | \alias{scplot} 5 | \title{Plot Synthetic Control Point Estimates and Prediction Interval} 6 | \usage{ 7 | scplot( 8 | result, 9 | fig.path = NULL, 10 | fig.name = NULL, 11 | fig.format = "png", 12 | e.out = TRUE, 13 | joint = FALSE, 14 | col.treated = "black", 15 | col.synth = "mediumblue", 16 | label.xy = NULL, 17 | plot.range = NULL, 18 | x.ticks = NULL, 19 | event.label = NULL, 20 | plot.specs = NULL, 21 | save.data = NULL 22 | ) 23 | } 24 | \arguments{ 25 | \item{result}{a class 'scest' object, obtained by calling \code{\link{scest}}, or a class 26 | 'scpi' object, obtained by calling \code{\link{scpi}}.} 27 | 28 | \item{fig.path}{a string indicating the path where the plot(s) should be saved.} 29 | 30 | \item{fig.name}{a string indicating the name of the plot(s). If multiple plots will be saved the command automatically 31 | generates a numeric suffix to avoid overwriting them.} 32 | 33 | \item{fig.format}{a string indicating the format in which the plot(s) should be saved.} 34 | 35 | \item{e.out}{a logical specifying whether out-of-sample uncertainty should be included in the plot(s).} 36 | 37 | \item{joint}{a logical specifying whether simultaneous prediction intervals should be included in the plot(s). It requires \code{e.out = TRUE}.} 38 | 39 | \item{col.treated}{a string specifying the color for the treated unit series. Find the full list at \url{http://sape.inf.usi.ch/quick-reference/ggplot2/colour}.} 40 | 41 | \item{col.synth}{a string specifying the color for the synthetic unit series. Find the full list at \url{http://sape.inf.usi.ch/quick-reference/ggplot2/colour}.} 42 | 43 | \item{label.xy}{a character list with two elements indicating the name of the axes 44 | (eg. label.xy = list(x.lab = "Year", y.lab = "GDP growth (\%)")).} 45 | 46 | \item{plot.range}{a numeric array indicating the time range of the plot(s).} 47 | 48 | \item{x.ticks}{a numeric list containing the location of the ticks on the x axis.} 49 | 50 | \item{event.label}{a list containing a character object ('lab') indicating the label of the event and 51 | a numeric object indicating the height of the label in the plot.} 52 | 53 | \item{plot.specs}{a list containing some specifics to be passed to ggsave (eg. img.width, img.height, dpi)} 54 | 55 | \item{save.data}{a character specifying the name and the path of the saved dataframe containing the processed data used 56 | to produce the plot.} 57 | } 58 | \value{ 59 | \item{plots}{a list containing standard ggplot object(s) that can be used for further customization.} 60 | } 61 | \description{ 62 | The command plots the actual pre-treatment and post-treatment series of the treated 63 | unit and the estimated counterfactual synthetic control unit with corresponding prediction intervals. 64 | Prediction intervals can take into account either in-sample uncertainty only or in-sample and 65 | out-of-sample uncertainty using the techniques developed in \href{https://nppackages.github.io/references/Cattaneo-Feng-Titiunik_2021_JASA.pdf}{Cattaneo, Feng, and Titiunik (2021)}. \code{\link{scpi}}. 66 | The input object should come from the command \code{\link{scest}} or from the command \code{\link{scpi}}. 67 | 68 | Companion \href{https://www.stata.com/}{Stata} and \href{https://www.python.org/}{Python} packages are described in \href{https://arxiv.org/abs/2202.05984}{Cattaneo, Feng, Palomba, and Titiunik (2022)}. 69 | 70 | Companion commands are: \link{scdata} and \link{scdataMulti} for data preparation in the single and multiple treated unit(s) cases, respectively, 71 | \link{scest} for point estimation, \link{scpi} for inference procedures, and \link{scplotMulti} for plots with multiple treated units. 72 | 73 | Related Stata, R, and Python packages useful for inference in SC designs are described in the following website: 74 | 75 | \href{ https://nppackages.github.io/scpi/}{ https://nppackages.github.io/scpi/} 76 | 77 | For an introduction to synthetic control methods, see \href{https://www.aeaweb.org/articles?id=10.1257/jel.20191450}{Abadie (2021)} and references therein. 78 | } 79 | \examples{ 80 | 81 | data <- scpi_germany 82 | 83 | df <- scdata(df = data, id.var = "country", time.var = "year", 84 | outcome.var = "gdp", period.pre = (1960:1990), 85 | period.post = (1991:2003), unit.tr = "West Germany", 86 | unit.co = setdiff(unique(data$country), "West Germany"), 87 | constant = TRUE, cointegrated.data = TRUE) 88 | 89 | result <- scest(df, w.constr = list(name = "simplex", Q = 1)) 90 | 91 | scplot(result) 92 | 93 | } 94 | \references{ 95 | \itemize{ 96 | \item{\href{https://www.aeaweb.org/articles?id=10.1257/jel.20191450}{Abadie, A. (2021)}. Using synthetic controls: 97 | Feasibility, data requirements, and methodological aspects. 98 | \emph{Journal of Economic Literature}, 59(2), 391-425.} 99 | \item{\href{https://nppackages.github.io/references/Cattaneo-Feng-Titiunik_2021_JASA.pdf}{Cattaneo, M. D., Feng, Y., and Titiunik, R. 100 | (2021)}. Prediction intervals for synthetic control methods. \emph{Journal of the American Statistical Association}, 116(536), 1865-1880.} 101 | \item{\href{https://arxiv.org/abs/2202.05984}{Cattaneo, M. D., Feng, Y., Palomba F., and Titiunik, R. (2022)}, 102 | scpi: Uncertainty Quantification for Synthetic Control Methods, \emph{arXiv}:2202.05984.} 103 | \item{\href{https://arxiv.org/abs/2210.05026}{Cattaneo, M. D., Feng, Y., Palomba F., and Titiunik, R. (2022).} 104 | Uncertainty Quantification in Synthetic Controls with Staggered Treatment Adoption, \emph{arXiv}:2210.05026.} 105 | } 106 | } 107 | \seealso{ 108 | \code{\link{scdata}}, \code{\link{scdataMulti}}, \code{\link{scest}}, \code{\link{scpi}}, \code{\link{scplotMulti}} 109 | } 110 | \author{ 111 | Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 112 | 113 | Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 114 | 115 | Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 116 | 117 | Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 118 | } 119 | -------------------------------------------------------------------------------- /R/scpi/man/scplotMulti.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scplotMulti.R 3 | \name{scplotMulti} 4 | \alias{scplotMulti} 5 | \title{Plot Synthetic Control Point Estimates and Prediction Interval With Multiple Treated units and Staggered Adoption} 6 | \usage{ 7 | scplotMulti( 8 | result, 9 | type = "series", 10 | e.out = TRUE, 11 | joint = FALSE, 12 | col.treated = "black", 13 | col.synth = "mediumblue", 14 | scales = "fixed", 15 | point.size = 1.5, 16 | ncols = 3, 17 | save.data = NULL, 18 | verbose = TRUE 19 | ) 20 | } 21 | \arguments{ 22 | \item{result}{a class 'scest' object, obtained by calling \code{\link{scest}}, or a class 23 | 'scpi' object, obtained by calling \code{\link{scpi}}. The data object given as input to this command has to be 24 | processed with \code{\link{scdataMulti}}.} 25 | 26 | \item{type}{a character that specifies the type of plot to be produced. If set to 'treatment' then treatment effects are plotted. 27 | If set to 'series' (default), the actual and synthetic time series are reported.} 28 | 29 | \item{e.out}{a logical specifying whether out-of-sample uncertainty should be included in the plot(s).} 30 | 31 | \item{joint}{a logical specifying whether simultaneous prediction intervals should be included in the plot(s). It requires \code{e.out = TRUE}.} 32 | 33 | \item{col.treated}{a string specifying the color for the treated unit series. Find the full list at \url{http://sape.inf.usi.ch/quick-reference/ggplot2/colour}.} 34 | 35 | \item{col.synth}{a string specifying the color for the synthetic unit series. Find the full list at \url{http://sape.inf.usi.ch/quick-reference/ggplot2/colour}.} 36 | 37 | \item{scales}{should axes scales be fixed ("fixed", the default), free ("free"), or free in one dimension ("free_x", "free_y")?} 38 | 39 | \item{point.size}{a scalar controlling the size of points in the scatter plot. Default is 1.5.} 40 | 41 | \item{ncols}{an integer controlling the number of columns in the plot.} 42 | 43 | \item{save.data}{a character specifying the name and the path of the saved dataframe containing the processed data used to produce the plot.} 44 | 45 | \item{verbose}{if \code{TRUE} prints additional information in the console.} 46 | } 47 | \value{ 48 | \item{plots}{a list containing standard ggplot object(s) that can be used for further customization.} 49 | } 50 | \description{ 51 | The command produces a wide range of plots of Synthetic Control estimates and corresponding prediction intervals. The command allows form multiple treated units and staggered adoption. 52 | Prediction intervals can take into account either in-sample uncertainty only or in-sample and 53 | out-of-sample uncertainty using the techniques developed in \href{https://nppackages.github.io/references/Cattaneo-Feng-Titiunik_2021_JASA.pdf}{Cattaneo, Feng, and Titiunik (2021)}. \code{\link{scpi}}. 54 | The input object should come from the command \code{\link{scest}} or from the command \code{\link{scpi}}. 55 | 56 | Companion \href{https://www.stata.com/}{Stata} and \href{https://www.python.org/}{Python} packages are described in \href{https://arxiv.org/abs/2202.05984}{Cattaneo, Feng, Palomba, and Titiunik (2022)}. 57 | 58 | Companion commands are: \link{scdata} and \link{scdataMulti} for data preparation in the single and multiple treated unit(s) cases, respectively, 59 | \link{scest} for point estimation, \link{scpi} for inference procedures, and \link{scplotMulti} for plots with multiple treated units. 60 | 61 | Related Stata, R, and Python packages useful for inference in SC designs are described in the following website: 62 | 63 | \href{ https://nppackages.github.io/scpi/}{ https://nppackages.github.io/scpi/} 64 | 65 | For an introduction to synthetic control methods, see \href{https://www.aeaweb.org/articles?id=10.1257/jel.20191450}{Abadie (2021)} and references therein. 66 | } 67 | \examples{ 68 | 69 | datager <- scpi_germany 70 | 71 | datager$tr_id <- 0 72 | datager$tr_id[(datager$country == "West Germany" & datager$year > 1990)] <- 1 73 | datager$tr_id[(datager$country == "Italy" & datager$year > 1992)] <- 0 74 | 75 | outcome.var <- "gdp" 76 | id.var <- "country" 77 | treatment.var <- "tr_id" 78 | time.var <- "year" 79 | df.unit <- scdataMulti(datager, id.var = id.var, outcome.var = outcome.var, 80 | treatment.var = treatment.var, 81 | time.var = time.var, features = list(c("gdp", "trade")), 82 | cointegrated.data = TRUE, constant = TRUE) 83 | 84 | res.unit <- scpi(df.unit, sims = 10, cores = 1) 85 | scplotMulti(res.unit, joint = TRUE) 86 | 87 | } 88 | \references{ 89 | \itemize{ 90 | \item{\href{https://www.aeaweb.org/articles?id=10.1257/jel.20191450}{Abadie, A. (2021)}. Using synthetic controls: Feasibility, data requirements, and methodological aspects. 91 | \emph{Journal of Economic Literature}, 59(2), 391-425.} 92 | \item{\href{https://nppackages.github.io/references/Cattaneo-Feng-Titiunik_2021_JASA.pdf}{Cattaneo, M. D., Feng, Y., and Titiunik, R. 93 | (2021)}. Prediction intervals for synthetic control methods. \emph{Journal of the American Statistical Association}, 116(536), 1865-1880.} 94 | \item{\href{https://arxiv.org/abs/2202.05984}{Cattaneo, M. D., Feng, Y., Palomba F., and Titiunik, R. (2022)}, 95 | scpi: Uncertainty Quantification for Synthetic Control Methods, \emph{arXiv}:2202.05984.} 96 | \item{\href{https://arxiv.org/abs/2210.05026}{Cattaneo, M. D., Feng, Y., Palomba F., and Titiunik, R. (2022).} 97 | Uncertainty Quantification in Synthetic Controls with Staggered Treatment Adoption, \emph{arXiv}:2210.05026.} 98 | } 99 | } 100 | \seealso{ 101 | \code{\link{scdata}}, \code{\link{scdataMulti}}, \code{\link{scest}}, \code{\link{scpi}}, \code{\link{scplotMulti}} 102 | } 103 | \author{ 104 | Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 105 | 106 | Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 107 | 108 | Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 109 | 110 | Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 111 | } 112 | -------------------------------------------------------------------------------- /R/scpi/man/summary.scdata.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scdata_methods.R 3 | \name{summary.scdata} 4 | \alias{summary.scdata} 5 | \title{Summary Method for Synthetic Control Prediction} 6 | \usage{ 7 | \method{summary}{scdata}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{Class "scest" object, obtained by calling \code{\link{scdata}}.} 11 | 12 | \item{...}{Additional arguments} 13 | } 14 | \value{ 15 | No return value, called to summarize \code{\link{scdata}} results. 16 | } 17 | \description{ 18 | The summary method for synthetic control prediction objects. 19 | } 20 | \seealso{ 21 | \code{\link{scdata}} 22 | 23 | Supported methods: \code{\link{print.scdata}}, \code{\link{summary.scdata}}. 24 | } 25 | \author{ 26 | Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 27 | 28 | Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 29 | 30 | Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 31 | 32 | Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 33 | } 34 | -------------------------------------------------------------------------------- /R/scpi/man/summary.scdataMulti.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scdataMulti_methods.R 3 | \name{summary.scdataMulti} 4 | \alias{summary.scdataMulti} 5 | \title{Summary Method for Synthetic Control Prediction} 6 | \usage{ 7 | \method{summary}{scdataMulti}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{Class "scdataMulti" object, obtained by calling \code{\link{scdataMulti}}.} 11 | 12 | \item{...}{Additional arguments} 13 | } 14 | \value{ 15 | No return value, called to summarize \code{\link{scdataMulti}} results. 16 | } 17 | \description{ 18 | The summary method for synthetic control prediction objects. 19 | } 20 | \seealso{ 21 | \code{\link{scdataMulti}} 22 | 23 | Supported methods: \code{\link{print.scdataMulti}}, \code{\link{summary.scdataMulti}}. 24 | } 25 | \author{ 26 | Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 27 | 28 | Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 29 | 30 | Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 31 | 32 | Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 33 | } 34 | -------------------------------------------------------------------------------- /R/scpi/man/summary.scest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scest_methods.R 3 | \name{summary.scest} 4 | \alias{summary.scest} 5 | \title{Summary Method for Synthetic Control Prediction} 6 | \usage{ 7 | \method{summary}{scest}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{Class "scest" object, obtained by calling \code{\link{scest}}.} 11 | 12 | \item{...}{Additional arguments} 13 | } 14 | \value{ 15 | No return value, called to summarize \code{\link{scest}} results. 16 | } 17 | \description{ 18 | The summary method for synthetic control prediction fitted objects. 19 | } 20 | \seealso{ 21 | \code{\link{scest}} 22 | 23 | Supported methods: \code{\link{print.scest}}, \code{\link{summary.scest}}, \code{\link{coef.scest}}. 24 | } 25 | \author{ 26 | Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 27 | 28 | Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 29 | 30 | Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 31 | 32 | Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 33 | } 34 | -------------------------------------------------------------------------------- /R/scpi/man/summary.scpi.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scpi_methods.R 3 | \name{summary.scpi} 4 | \alias{summary.scpi} 5 | \title{Summary Method for Synthetic Control Inference} 6 | \usage{ 7 | \method{summary}{scpi}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{Class "scpi" object, obtained by calling \code{\link{scpi}}.} 11 | 12 | \item{...}{Additional arguments} 13 | } 14 | \value{ 15 | No return value, called to summarize \code{\link{scpi}} results. 16 | } 17 | \description{ 18 | The summary method for synthetic control inference objects. 19 | } 20 | \seealso{ 21 | \code{\link{scpi}} 22 | 23 | Supported methods: \code{\link{print.scpi}}, \code{\link{summary.scpi}}. 24 | } 25 | \author{ 26 | Matias Cattaneo, Princeton University. \email{cattaneo@princeton.edu}. 27 | 28 | Yingjie Feng, Tsinghua University. \email{fengyj@sem.tsinghua.edu.cn}. 29 | 30 | Filippo Palomba, Princeton University (maintainer). \email{fpalomba@princeton.edu}. 31 | 32 | Rocio Titiunik, Princeton University. \email{titiunik@princeton.edu}. 33 | } 34 | -------------------------------------------------------------------------------- /R/scpi/tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(scpi) 3 | 4 | test_check("scpi") 5 | -------------------------------------------------------------------------------- /R/scpi/tests/testthat/test-scdataMulti.R: -------------------------------------------------------------------------------- 1 | library(scpi) 2 | 3 | ############################################################################### 4 | ############################################################################### 5 | ## Auxiliary functions for testing 6 | 7 | test.data <- function(df, 8 | features = NULL, 9 | cov.adj = NULL, 10 | cointegrated.data = FALSE, 11 | post.est = NULL, 12 | units.est = NULL, 13 | donors.est = NULL, 14 | anticipation = 0, 15 | effect = "unit-time", 16 | constant = FALSE, 17 | verbose = FALSE, 18 | sparse.matrices = FALSE) { 19 | data <- scpi_germany 20 | 21 | # Create a second placebo treated unit 22 | data$treatment <- 0 23 | data[(data$country == "West Germany" & data$year >= 1991), "treatment"] <- 1 24 | data[(data$country == "Italy" & data$year >= 1992), "treatment"] <- 1 25 | 26 | df <- scdataMulti(data, id.var = "country", outcome.var = "gdp", 27 | treatment.var = "treatment", time.var = "year", constant = constant, 28 | cointegrated.data = cointegrated.data, features = features, 29 | cov.adj = cov.adj, verbose = verbose, post.est = post.est, 30 | units.est = units.est, donors.est = donors.est, anticipation = anticipation, 31 | effect = effect, sparse.matrices = sparse.matrices) 32 | 33 | return(df) 34 | } 35 | 36 | ############################################################################### 37 | ############################################################################### 38 | ## Auxiliary functions for testing 39 | 40 | test_that("no error is returned", { 41 | expect_no_error(test.data(constant = TRUE, sparse.matrices=FALSE, effect="unit-time", 42 | cointegrated.data = TRUE, features = list(c("gdp", "trade")), 43 | cov.adj = list(c("constant", "trend")))) 44 | expect_no_error(test.data(constant = TRUE, sparse.matrices=FALSE, effect="time", 45 | cointegrated.data = TRUE, features = list(c("gdp", "trade")), 46 | cov.adj = list(c("constant", "trend")))) 47 | expect_no_error(test.data(constant = TRUE, sparse.matrices=FALSE, effect="unit", 48 | cointegrated.data = TRUE, features = list(c("gdp", "trade")), 49 | cov.adj = list(c("constant", "trend")))) 50 | expect_no_error(test.data(constant = TRUE, sparse.matrices=FALSE, effect="unit", post=5, 51 | cointegrated.data = TRUE, features = list(c("gdp", "trade")), 52 | cov.adj = list(c("constant", "trend")))) 53 | }) 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /R/scpi/tests/testthat/test-scpi.R: -------------------------------------------------------------------------------- 1 | library(scpi) 2 | 3 | ############################################################################### 4 | ############################################################################### 5 | ## Auxiliary functions for testing 6 | 7 | test.data <- function(df = NULL, 8 | id.var = "country", 9 | time.var = "year", 10 | outcome.var = "gdp", 11 | period.pre = (1960:1990), 12 | period.post = (1991:1997), 13 | unit.tr = "West Germany", 14 | unit.co = NULL, 15 | features = NULL, 16 | cov.adj = NULL, 17 | cointegrated.data = FALSE, 18 | anticipation = 0, 19 | constant = TRUE) { 20 | 21 | 22 | if (is.null(df)) df <- scpi_germany 23 | if (is.null(unit.co)) unit.co <- unique(df$country)[-7] 24 | 25 | out <- scdata(df = df, id.var = id.var, time.var = time.var, outcome.var = outcome.var, 26 | period.pre = period.pre, period.post = period.post, 27 | unit.tr = unit.tr, unit.co = unit.co, cov.adj = cov.adj, features = features, 28 | constant = constant, cointegrated.data = cointegrated.data) 29 | 30 | return(out) 31 | } 32 | 33 | ############################################################################### 34 | ############################################################################### 35 | 36 | 37 | test_that("an error is returned", 38 | { 39 | test_obj <- test.data() 40 | xx <- matrix(0,30,30) 41 | expect_error(scpi(xx, verbose = F)) 42 | expect_error(scpi(test_obj, w.constr = "ols", cores = 2, verbose = F)) 43 | expect_error(scpi(test_obj, w.constr = list(name="wrong name"), cores = 2, verbose = F)) 44 | expect_error(scpi(test_obj, w.constr = list(lb = - Inf, p = 2, dir = "<=", Q = 1), cores = 2, verbose = F)) 45 | expect_error(scpi(test_obj, w.constr = list(lb = - Inf, p = "L1", dir = ">=", Q = 1), cores = 2, verbose = F)) 46 | expect_error(scpi(test_obj, w.constr = list(p = "L1", dir = "<="), cores = 2, verbose = F)) 47 | expect_error(scpi(test_obj, w.constr = list(lb = - Inf, dir = "<=", Q = 1), cores = 2, verbose = F)) 48 | expect_error(scpi(test_obj, w.constr = list(lb = - Inf, dir = "<="), cores = 2, verbose = F)) 49 | expect_error(scpi(test_obj, V = xx, cores = 2, verbose = F)) 50 | expect_error(scpi(test_obj, e.design = xx, cores = 2, verbose = F)) 51 | expect_error(scpi(test_obj, u.design = xx, cores = 2, verbose = F)) 52 | expect_error(scpi(test_obj, P = xx, cores = 2, verbose = F)) 53 | }) -------------------------------------------------------------------------------- /R/scpi_3.0.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/R/scpi_3.0.0.tar.gz -------------------------------------------------------------------------------- /R/scpi_illustration-multi.R: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## SCPI R Package 3 | ## R-file for Empirical Illustration - Multiple Treated Units 4 | ## Authors: Matias D. Cattaneo, Yingjie Feng, Filippo Palomba, and Rocio Titiunik 5 | ################################################################################ 6 | ### Clear R environment 7 | rm(list = ls(all = TRUE)) 8 | 9 | ### Install R library 10 | #install.packages("scpi") 11 | 12 | ### Load SCPI package 13 | library(scpi) 14 | 15 | set.seed(8894) 16 | 17 | ############################################################################### 18 | # MULTIPLE TREATED UNITS 19 | ############################################################################### 20 | 21 | ### Load data 22 | data <- scpi_germany 23 | 24 | # Create a second placebo treated unit 25 | data$treatment <- 0 26 | data[(data$country == "West Germany" & data$year >= 1991), "treatment"] <- 1 27 | data[(data$country == "Italy" & data$year >= 1992), "treatment"] <- 1 28 | 29 | 30 | ###################################################### 31 | # unit-time treatment effect (\tau_{ik}) 32 | ###################################################### 33 | 34 | df <- scdataMulti(data, id.var = "country", outcome.var = "gdp", 35 | treatment.var = "treatment", time.var = "year", constant = TRUE, 36 | cointegrated.data = TRUE, features = list(c("gdp", "trade")), 37 | cov.adj = list(c("constant", "trend"))) 38 | 39 | 40 | res <- scest(df, w.constr = list("name" = "simplex")) 41 | scplotMulti(res) 42 | ggsave("germany_est_multi_1.png", height=6, width=9, dpi="retina") 43 | 44 | 45 | respi <- scpi(df, w.constr = list("name" = "simplex"), cores = 1, sims = 50, 46 | e.method = "gaussian") 47 | 48 | # plot series 49 | scplotMulti(respi, type = "series") 50 | ggsave("germany_est_multi_2.png", height=6, width=9, dpi="retina") 51 | 52 | # plot treatment 53 | scplotMulti(respi, type = "series", joint = TRUE) 54 | ggsave("germany_est_multi_3.png", height=6, width=9, dpi="retina") 55 | 56 | 57 | ###################################################### 58 | # average unit treatment effect (\tau_{i.}) 59 | ###################################################### 60 | 61 | df <- scdataMulti(data, id.var = "country", outcome.var = "gdp", 62 | treatment.var = "treatment", time.var = "year", constant = TRUE, 63 | cointegrated.data = TRUE, features = list(c("gdp", "trade")), 64 | cov.adj = list(c("constant", "trend")), effect = "unit") 65 | 66 | res <- scest(df, w.constr = list("name" = "simplex")) 67 | scplotMulti(res) 68 | ggsave("germany_est_multi_4.png", height=6, width=9, dpi="retina") 69 | 70 | respi <- scpi(df, w.constr = list("name" = "simplex"), cores = 1, sims = 50, 71 | e.method = "gaussian") 72 | 73 | # plot series 74 | scplotMulti(respi, type = "series") 75 | ggsave("germany_est_multi_5.png", height=6, width=9, dpi="retina") 76 | 77 | # plot treatment 78 | scplotMulti(respi, type = "series", joint = TRUE) 79 | ggsave("germany_est_multi_6.png", height=6, width=9, dpi="retina") 80 | 81 | ###################################################### 82 | # average treatment effect on the treated (\tau_{.k}) 83 | ###################################################### 84 | 85 | df <- scdataMulti(data, id.var = "country", outcome.var = "gdp", 86 | treatment.var = "treatment", time.var = "year", constant = TRUE, 87 | cointegrated.data = TRUE, features = list(c("gdp", "trade")), 88 | cov.adj = list(c("constant", "trend")), effect = "time") 89 | 90 | res <- scest(df, w.constr = list("name" = "simplex")) 91 | scplotMulti(res) 92 | ggsave("germany_est_multi_7.png", height=6, width=9, dpi="retina") 93 | 94 | respi <- scpi(df, w.constr = list("name" = "simplex"), cores = 1, sims = 50, 95 | e.method = "gaussian") 96 | 97 | # plot series 98 | scplotMulti(respi, type = "series") 99 | ggsave("germany_est_multi_8.png", height=6, width=9, dpi="retina") 100 | 101 | # plot treatment 102 | scplotMulti(respi, type = "series", joint = TRUE) 103 | ggsave("germany_est_multi_9.png", height=6, width=9, dpi="retina") 104 | -------------------------------------------------------------------------------- /R/scpi_illustration_plot-multi.R: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ## SCPI R Package 3 | ## R-file for Empirical Illustration - Multiple Treated Units 4 | ## Authors: Matias D. Cattaneo, Yingjie Feng, Filippo Palomba, and Rocio Titiunik 5 | ################################################################################ 6 | ### Clear R environment 7 | rm(list=ls(all=TRUE)) 8 | 9 | ### Install R library 10 | #install.packages('scpi') 11 | 12 | ### Load packages 13 | library(scpi) 14 | library(ggplot2) 15 | 16 | set.seed(8894) 17 | theme_set(theme_bw()) 18 | 19 | ############################################################################### 20 | # MULTIPLE TREATED UNITS 21 | ############################################################################### 22 | 23 | ### Load data 24 | data <- scpi_germany 25 | 26 | data$treatment <- 0 27 | data[(data$country == "West Germany" & data$year >= 1991), 'treatment'] <- 1 28 | data[(data$country == "Italy" & data$year >= 1992), 'treatment'] <- 1 29 | 30 | 31 | ############################################### 32 | # unit-time treatment effect 33 | ############################################### 34 | 35 | df <- scdataMulti(data, id.var = "country", outcome.var = "gdp", 36 | treatment.var = "treatment", time.var = "year", constant = TRUE, 37 | cointegrated.data = T, features = list(c("gdp","trade")), 38 | cov.adj = list(c("constant", "trend"))) 39 | 40 | res.pi <- scpi(df, w.constr = list("name" = "simplex"), cores = 1, sims = 50, 41 | e.method = "gaussian") 42 | 43 | # plot series 44 | scplotMulti(res.pi, type = "series", joint = TRUE, save.data = '__scpi_data') 45 | 46 | load('__scpi_data.RData') 47 | 48 | plot <- ggplot(toplot) + xlab("Date") + ylab("Outcome") + 49 | geom_line(aes(x=Time, y=Y, colour=Type)) + 50 | geom_point(aes(x=Time, y=Y, colour=Type), size=1.5) + 51 | geom_vline(aes(xintercept=Tdate)) + 52 | facet_wrap(~ID, ncol = 2) + theme(legend.position="bottom") + 53 | scale_color_manual(name = "", values = c("black", "blue"), 54 | labels = c("Treated", "Synthetic Control")) 55 | 56 | plot.w1 <- plot + geom_errorbar(data = toplot, 57 | aes(x = Time, ymin = lb.gaussian, ymax = ub.gaussian), colour = "blue", 58 | width = 0.5, linetype = 1) + ggtitle("In and Out of Sample Uncertainty - Subgaussian Bounds") 59 | 60 | plotdf <- subset(toplot, Type == "Synthetic") 61 | plot.w1 + geom_ribbon(data=plotdf, aes(x=Time, ymin=lb.joint, ymax=ub.joint), fill="blue", alpha=0.1) 62 | 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SCPI 2 | 3 | The `scpi` package provides Python, R and Stata implementations of estimation and inference procedures for synthetic control methods. 4 | 5 | This work was supported by the National Science Foundation through grants [SES-1947805](https://www.nsf.gov/awardsearch/showAward?AWD_ID=1947805), [SES-2019432](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2019432), and [SES-2241575](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2241575), and by the National Institutes of Health through grant [R01 GM072611-16](https://reporter.nih.gov/project-details/10093056). 6 | 7 | ## Queries and Requests 8 | 9 | Please email: [scpi_pkg@googlegroups.com](mailto:scpi_pkg@googlegroups.com) 10 | 11 | ## Python Implementation 12 | 13 | To install/update in Python type: 14 | ``` 15 | pip install scpi_pkg 16 | ``` 17 | 18 | - Help: [PyPI repository](https://pypi.org/project/scpi_pkg/). 19 | 20 | - Replication: [py-script](Python/scpi_illustration.py), [plot illustration](Python/scpi_illustration_plot.py), [data](Python/scpi_germany.csv). 21 | 22 | - Illustration Staggered Adoption: [py-script](Python/scpi_illustration-multi.py), [plot illustration](Python/scpi_illustration_plot-multi.py). 23 | 24 | ## R Implementation 25 | 26 | To install/update in R from CRAN type: 27 | ``` 28 | install.packages('scpi') 29 | ```` 30 | 31 | - Help: [R Manual](https://cran.r-project.org/web/packages/scpi/scpi.pdf), [CRAN repository](https://cran.r-project.org/package=scpi). 32 | 33 | - Replication: [R-script](R/scpi_illustration.R), [plot illustration](R/scpi_illustration_plot.R), [data](R/scpi_germany.csv). 34 | 35 | - Illustration Staggered Adoption: [R-script](R/scpi_illustration-multi.R), [plot illustration](R/scpi_illustration_plot-multi.R). 36 | 37 | ## Stata Implementation 38 | 39 | The Stata implementation relies on Python, which needs to be available in the system. 40 | 41 | ### How to install Python 42 | There are at least two ways to install Python: 43 | 1. Download and install Python directly from [https://realpython.com/installing-python/](https://realpython.com/installing-python/). 44 | 2. Download and install Anaconda for [Windows](https://docs.anaconda.com/anaconda/install/windows/), [macOS](https://docs.anaconda.com/anaconda/install/mac-os/), or [Linux](https://docs.anaconda.com/anaconda/install/linux/). 45 | 46 | After Python is installed, please run the following two commands via the Python command line: 47 | 48 | ``` 49 | pip install luddite 50 | pip install scpi_pkg 51 | ``` 52 | 53 | ### How to link Stata and Python 54 | Stata (16.0 or newer) and Python (>=3.8) can be linked following the [official tutorial](https://blog.stata.com/2020/08/18/stata-python-integration-part-1-setting-up-stata-to-use-python/) on the Stata blog. 55 | 56 | ### To install/update in Stata type: 57 | ``` 58 | net install grc1leg, from("http://www.stata.com/users/vwiggins/") replace force 59 | net install scpi, from(https://raw.githubusercontent.com/nppackages/scpi/master/stata) replace force 60 | ``` 61 | 62 | - Help: [scdata](stata/scdata.pdf), [scest](/stata/scest.pdf), [scpi](stata/scpi.pdf), [scplot](stata/scplot.pdf). 63 | 64 | - Replication files: [do-file](stata/scpi_illustration.do), [plot illustration](stata/scpi_illustration_plot.do), [data](stata/scpi_germany.dta). 65 | 66 | - Illustration Staggered Adoption: [do-file](stata/scpi_illustration-multi.do), [plot illustration](stata/scpi_illustration_plot-multi.do). 67 | 68 | 69 | ## References 70 | 71 | ### Software and Implementation 72 | 73 | - Cattaneo, Feng, Palomba and Titiunik (2025): [scpi: Uncertainty Quantification for Synthetic Control Methods](https://nppackages.github.io/references/Cattaneo-Feng-Palomba-Titiunik_2025_JSS.pdf).
74 | _Journal of Statistical Software_, forthcoming. 75 | 76 | ### Technical and Methodological 77 | 78 | - Cattaneo, Feng, Palomba and Titiunik (2025): [Uncertainty Quantification in Synthetic Controls with Staggered Treatment Adoption](https://nppackages.github.io/references/Cattaneo-Feng-Palomba-Titiunik_2025_RESTAT.pdf).
79 | _Review of Economics and Statistics_, revise and resubmit.
80 | [Supplemental](https://nppackages.github.io/references/Cattaneo-Feng-Palomba-Titiunik_2025_RESTAT--Supplement.pdf)
81 | 82 | - Cattaneo, Feng and Titiunik (2021): [Prediction Intervals for Synthetic Control Methods](https://nppackages.github.io/references/Cattaneo-Feng-Titiunik_2021_JASA.pdf).
83 | _Journal of the American Statistical Association_ 116(536): 1865-1880.
84 | [Supplemental](https://nppackages.github.io/references/Cattaneo-Feng-Titiunik_2021_JASA--Supplement.pdf)
85 | 86 |

87 | -------------------------------------------------------------------------------- /python/scpi_pkg/dist/scpi_pkg-3.0.0-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/python/scpi_pkg/dist/scpi_pkg-3.0.0-py3-none-any.whl -------------------------------------------------------------------------------- /python/scpi_pkg/dist/scpi_pkg-3.0.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/python/scpi_pkg/dist/scpi_pkg-3.0.0.tar.gz -------------------------------------------------------------------------------- /python/scpi_pkg/src/scpi_pkg/__pycache__/funs.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/python/scpi_pkg/src/scpi_pkg/__pycache__/funs.cpython-312.pyc -------------------------------------------------------------------------------- /python/scpi_pkg/src/scpi_pkg/__pycache__/scdata.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/python/scpi_pkg/src/scpi_pkg/__pycache__/scdata.cpython-312.pyc -------------------------------------------------------------------------------- /python/scpi_pkg/src/scpi_pkg/__pycache__/scdataMulti.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/python/scpi_pkg/src/scpi_pkg/__pycache__/scdataMulti.cpython-312.pyc -------------------------------------------------------------------------------- /python/scpi_pkg/src/scpi_pkg/__pycache__/scest.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/python/scpi_pkg/src/scpi_pkg/__pycache__/scest.cpython-312.pyc -------------------------------------------------------------------------------- /python/scpi_pkg/src/scpi_pkg/__pycache__/scpi.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/python/scpi_pkg/src/scpi_pkg/__pycache__/scpi.cpython-312.pyc -------------------------------------------------------------------------------- /python/scpi_pkg/src/scpi_pkg/__pycache__/scplot.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/python/scpi_pkg/src/scpi_pkg/__pycache__/scplot.cpython-312.pyc -------------------------------------------------------------------------------- /python/scpi_pkg/src/scpi_pkg/__pycache__/scplotMulti.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/python/scpi_pkg/src/scpi_pkg/__pycache__/scplotMulti.cpython-312.pyc -------------------------------------------------------------------------------- /stata/scdata.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/stata/scdata.pdf -------------------------------------------------------------------------------- /stata/scdatamulti.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/stata/scdatamulti.pdf -------------------------------------------------------------------------------- /stata/scest.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/stata/scest.pdf -------------------------------------------------------------------------------- /stata/scpi.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/stata/scpi.pdf -------------------------------------------------------------------------------- /stata/scpi.pkg: -------------------------------------------------------------------------------- 1 | v 3 2 | d STATA Package: SCPI 3 | d 4 | d Authors: Matias D. Cattaneo, Princeton University, cattaneo@princeton.edu 5 | d Yingjie Feng, Tsinghua University, fengyingjiepku@gmail.com 6 | d Filippo Palomba, Princeton University, fpalomba@princeton.edu 7 | d Rocio Titiunik, Princeton University, titiunik@princeton.edu 8 | d 9 | d Date: 31-JAN-2025 10 | d Distribution-Date: 20250131 11 | d 12 | f scdata.ado 13 | f scdata.sthlp 14 | f scdatamulti.ado 15 | f scdatamulti.sthlp 16 | f scest.ado 17 | f scest.sthlp 18 | f scpi.ado 19 | f scpi.sthlp 20 | f scpi_germany.dta 21 | f scplot.ado 22 | f scplot.sthlp 23 | f scplotmulti.ado 24 | f scplotmulti.sthlp -------------------------------------------------------------------------------- /stata/scpi_germany.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/stata/scpi_germany.dta -------------------------------------------------------------------------------- /stata/scpi_illustration-multi.do: -------------------------------------------------------------------------------- 1 | ****************************************************************************************** 2 | ** SCPI Stata Package 3 | ** Do-file for Empirical Illustration - Multiple Treated Unit 4 | ** Authors: Matias D. Cattaneo, Yingjie Feng, Filippo Palomba and Rocio Titiunik 5 | ****************************************************************************************** 6 | 7 | ****************************************************************************************** 8 | ** net install scpi, from(https://raw.githubusercontent.com/nppackages/scpi/master/stata) replace 9 | ****************************************************************************************** 10 | clear all 11 | set more off 12 | set linesize 80 13 | 14 | ****************************************************************************************** 15 | ****************************************************************************************** 16 | ** MULTIPLE TREATED UNITS 17 | ****************************************************************************************** 18 | ****************************************************************************************** 19 | 20 | use "scpi_germany.dta", clear 21 | 22 | * Create a second placebo treated unit 23 | replace status = 1 if country == "Italy" & year >= 1992 24 | 25 | ****************************************************************************************** 26 | ** prepare data - one feature, cointegrated data, unit-time treatment effect 27 | ****************************************************************************************** 28 | 29 | global coint "True" 30 | global consta "True" 31 | global covs "constant, trend" 32 | 33 | scdatamulti gdp trade, dfname("python_scdatamulti") /// 34 | id(country) outcome(gdp) time(year) treatment(status) cointegrated($coint) /// 35 | constant($consta) covadj($covs) pypinocheck 36 | 37 | scest, dfname("python_scdatamulti") name(simplex) 38 | scplotmulti, scest 39 | 40 | scpi, dfname("python_scdatamulti") name(simplex) sims(50) set_seed(8894) 41 | 42 | * plot series 43 | scplotmulti, uncertainty("gaussian") ptype("series") 44 | 45 | * plot treatment effects 46 | scplotmulti, uncertainty("gaussian") ptype("treatment") joint 47 | 48 | 49 | ****************************************************************************************** 50 | ** prepare data - one feature, cointegrated data, average unit post-treatment effect 51 | ****************************************************************************************** 52 | 53 | * note that you can flexibly specify options for different treated units! 54 | 55 | global coint "(Italy: True) (West Germany: False)" 56 | global consta "(Italy: True) (West Germany: False)" 57 | global covs "(Italy: constant, trend) (West Germany: constant, trend; constant, trend)" 58 | scdatamulti (Italy: gdp trade) (West Germany: gdp infrate), dfname("python_scdatamulti") /// 59 | id(country) outcome(gdp) time(year) treatment(status) cointegrated($coint) /// 60 | constant($consta) covadj($covs) effect("unit") 61 | 62 | scest, dfname("python_scdatamulti") name(simplex) 63 | scplotmulti, scest 64 | 65 | scpi, dfname("python_scdatamulti") name(simplex) sims(50) set_seed(8894) 66 | 67 | * plot series 68 | scplotmulti, uncertainty("gaussian") ptype("series") 69 | 70 | * plot treatment effects 71 | scplotmulti, uncertainty("gaussian") ptype("treatment") joint 72 | 73 | 74 | ****************************************************************************************** 75 | ** prepare data - one feature, cointegrated data, average treatment effect on the treated 76 | ****************************************************************************************** 77 | 78 | global coint "(Italy: True) (West Germany: False)" 79 | global consta "(Italy: True) (West Germany: False)" 80 | global covs "(Italy: constant, trend) (West Germany: constant, trend; constant, trend)" 81 | 82 | scdatamulti (Italy: gdp trade) (West Germany: gdp infrate), dfname("python_scdatamulti") /// 83 | id(country) outcome(gdp) time(year) treatment(status) cointegrated($coint) /// 84 | constant($consta) covadj($covs) effect("time") 85 | 86 | scest, dfname("python_scdatamulti") name(simplex) 87 | scplotmulti, scest 88 | 89 | scpi, dfname("python_scdatamulti") name(simplex) sims(50) set_seed(8894) 90 | 91 | * plot series 92 | scplotmulti, uncertainty("gaussian") ptype("series") 93 | 94 | * plot treatment effects 95 | scplotmulti, uncertainty("gaussian") ptype("treatment") joint 96 | 97 | 98 | erase "python_scdatamulti.obj" 99 | erase "__scest__output.obj" 100 | erase "__scpi__output.obj" 101 | -------------------------------------------------------------------------------- /stata/scpi_illustration_plot-multi.do: -------------------------------------------------------------------------------- 1 | ******************************************************************************** 2 | ** SCPI Stata Package 3 | ** Do-file for Visualization - Multiple Treated Units 4 | ** Authors: Matias D. Cattaneo, Yingjie Feng, Filippo Palomba and Rocio Titiunik 5 | ******************************************************************************** 6 | ** net install scpi, from(https://raw.githubusercontent.com/nppackages/scpi/master/stata) replace 7 | ******************************************************************************** 8 | 9 | * ssc install grc1leg 10 | 11 | ******************************************************************************** 12 | *** Multiple Treated Unit 13 | ******************************************************************************** 14 | 15 | ** Load data 16 | use "scpi_germany.dta", clear 17 | 18 | * suppose a second unit was treated 19 | replace status = 1 if country == "Italy" & year >= 1992 20 | 21 | ** Prepare data 22 | scdatamulti gdp, dfname("python_scdata") id(country) outcome(gdp) time(year) /// 23 | treatment(status) cointegrated(True) constant(True) 24 | 25 | ** SC - Inference 26 | set seed 8894 27 | scpi, dfname("python_scdata") name(simplex) u_missp sims(100) /// 28 | e_method(gaussian) set_seed(8894) 29 | 30 | scplotmulti , savedata("scplot_data") joint 31 | 32 | use "scplot_data.dta", clear 33 | 34 | drop __0000* 35 | global graph_names 36 | qui levelsof ID, local(tr_units) 37 | local plotname = 0 38 | foreach tr of local tr_units { 39 | 40 | local ++plotname 41 | qui su Tdate if ID == "`tr'" 42 | local tline = r(mean) 43 | 44 | twoway (rarea Lower_joint Upper_joint Time if Type == "Synthetic" & ID == "`tr'", color(blue%10) lcolor(blue%0)) /// 45 | (rcap Lower_gaussian Upper_gaussian Time if Type == "Synthetic" & ID == "`tr'", lpattern(solid) lwidth(medium) lcolor(blue)) /// 46 | (scatter Outcome Time if Type == "Actual" & ID == "`tr'", msymbol(Dh) msize(vsmall) mcolor(black)) /// 47 | (scatter Outcome Time if Type == "Synthetic" & ID == "`tr'", msymbol(Dh) msize(vsmall) mcolor(blue)) /// 48 | (line Outcome Time if Type == "Actual" & ID == "`tr'", lpattern(solid) lwidth(medium) lcolor(black)) /// 49 | (line Outcome Time if Type == "Synthetic" & ID == "`tr'", lpattern(solid) lwidth(medium) lcolor(blue)), /// 50 | ylabel(,nogrid) xline(`tline', lcolor(black) lpattern(dash)) ytitle("") xtitle("") title("") /// 51 | legend(order(5 6) lab(5 "Treated") lab(6 "Synthetic Control") region(style(none)) nobox size(vsmall)) /// 52 | graphregion(color(white)) plotregion(color(white)) scheme(s2manual) name("__gr__`plotname'", replace) nodraw 53 | 54 | global graph_names "$graph_names __gr__`plotname'" 55 | 56 | } 57 | 58 | grc1leg $graph_names, l1title("Outcome Variable", size(small)) b1title("Time", size(small)) graphregion(color(white)) plotregion(color(white)) scheme(s2manual) /// 59 | title("") ring(2) ycommon xcommon 60 | 61 | erase "scplot_data.dta" 62 | erase "python_scdata.obj" 63 | -------------------------------------------------------------------------------- /stata/scpi_illustration_plot.do: -------------------------------------------------------------------------------- 1 | ******************************************************************************** 2 | ** SCPI Stata Package 3 | ** Do-file for Visualization - Single Treated Unit 4 | ** Authors: Matias D. Cattaneo, Yingjie Feng, Filippo Palomba and Rocio Titiunik 5 | ******************************************************************************** 6 | ** net install scpi, from(https://raw.githubusercontent.com/nppackages/scpi/master/stata) replace 7 | ******************************************************************************** 8 | 9 | ******************************************************************************** 10 | *** Single Treated Unit 11 | ******************************************************************************** 12 | 13 | ** Load data 14 | use "scpi_germany.dta", clear 15 | 16 | ** Prepare data 17 | scdata gdp, dfname("python_scdata") id(country) outcome(gdp) time(year) /// 18 | treatment(status) cointegrated 19 | 20 | ** SC - Inference 21 | set seed 8894 22 | scpi, dfname("python_scdata") name(simplex) u_missp sims(100) /// 23 | e_method(gaussian) set_seed(8894) 24 | 25 | scplot , savedata("scplot_data") joint 26 | 27 | ** Load processed data 28 | use "scplot_data.dta", clear 29 | 30 | local tline = Tdate[1] 31 | 32 | twoway (rarea lbj ubj time, color(blue%10) lcolor(blue%0)) /// 33 | (rcap lb0 ub0 time, lpattern(solid) lwidth(medium) lcolor(blue)) /// 34 | (scatter y_act time, msymbol(Dh) msize(small) mcolor(black)) /// 35 | (scatter y_sc time, msymbol(Dh) msize(small) mcolor(blue)) /// 36 | (line y_act time, lpattern(solid) lwidth(medium) lcolor(black)) /// 37 | (line y_sc time, lpattern(dash) lwidth(medium) lcolor(blue)), /// 38 | ytitle("Outcome Variable") xtitle("Time") ylabel(,nogrid) /// 39 | xline(`tline', lcolor(black) lpattern(dash)) /// 40 | legend(order(5 6) lab(5 "Treated") lab(6 "Synthetic Control") /// 41 | region(style(none)) nobox) graphregion(color(white)) /// 42 | plotregion(color(white)) scheme(s2manual) /// 43 | note("In-and-out of sample Uncertainty - sub-Gaussian bounds") 44 | 45 | erase "scplot_data.dta" 46 | erase "python_scdata.obj" 47 | -------------------------------------------------------------------------------- /stata/scplot.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/stata/scplot.pdf -------------------------------------------------------------------------------- /stata/scplotmulti.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nppackages/scpi/52a11a24ed21c95c61d35d84e64715dcaaddd0f7/stata/scplotmulti.pdf -------------------------------------------------------------------------------- /stata/stata.toc: -------------------------------------------------------------------------------- 1 | v 3 2 | d SCPI: Point estimation and inference for Synthetic Control methods 3 | d https://nppackages.github.io/scpi/ 4 | d 5 | 6 | p scpi --------------------------------------------------------------------------------