Please note that installation should be done with a mixture of pip and direct installations in R so that the correct versions of packages are installed.
With pip for python:
pip install py_rdpackages
Important: you need to have the original rdrobust
installed in R:
install.packages('rdrobust')
Notes:
rdrobust
requires the newest version ofggplot2
so please:install.packages('ggplot2')
- The
rdrobust
andggplot2
versions in Anaconda lag behind the current release for R. Please install in R directly as opposed to through conda.
These packages are a work in progress, but are an attempt to create a wrapper to implement the wonderful RD packages found here (https://sites.google.com/site/rdpackages/rdrobust) which utilize R or Stata, so that they can be used in Python directly.
I utilize the graphics package of Seaborn to make the plots look nice and to enable additional features, like binning points by size.
There are three packages in py_rdpackages
:
rdplot
creates plots of the regression discontinuity with a variety of options.rdrobust
does the RD and reports the regression results.rdbwselect
selects the optimal bandwidth size.
The code in the testing folder produces the following example.
Use of the programs requires all of the following packages in Python:
rpy2
for running R in Pythonmatplotlib
andseaborn
for producing high quality graphicspandas
,numpy
and for data manipulation and dataframe reading
Currently tested and stable for:
rdrobust
version 0.99.9rpy2
version 2.9.4 (last version updated through conda -- may work for later versions)ggplot2
version 3.3.0
ryp2
produced slow pandas DF to R DF conversions, so I usepd.df.to_csv('temp_file_for_rd.csv')
as a solution and then delete that same file after doing the analysis. This should be fixed in future versions.- Of course, Python calling R and then converting back to python is not ideal. Some future version should code this from scratch.