Skip to main content

EconEnv

One Notebook. Multiple Econometric Engines.

Python, R, Stata and EViews in a single Jupyter workflow — on one Python kernel.

PyPI Python License: MIT Status: alpha

Install from PyPI · Documentation · Examples · Changelog


The problem

An applied econometrics paper rarely lives in one program. The unit-root test is in EViews because that is where the ARDL bounds output is readable. The panel estimator is in Stata because xtreg is the reference implementation. The plots are in R because ggplot2 is better. The data cleaning is in Python because pandas is better.

So the working day looks like this:

Python  →  to_csv()  →  Stata  →  export delimited  →  R  →  write.csv  →  EViews

Four programs open. Four windows. Four copies of the same data, drifting apart. A missing value that meant .a in Stata arriving as an empty cell in R. A quarterly index that became a string. And when a referee asks "why does your robust standard error differ from mine?", there is no way to answer without redoing the whole chain by hand.

The solution

EconEnv makes the four programs execution engines behind one Python kernel.

%load_ext econenv

df = pd.read_csv("data.csv")          # Python, as usual
%%R -i df
fit <- lm(y ~ x1 + x2, data = df)
summary(fit)
%%stata
regress y x1 x2
%%eviews -i df
equation eq1.ls y c x1 x2

One notebook. One kernel. One dataset. No CSV round-trip.

And then the part that is hard to do any other way:

econenv.compare_ols(df, "y ~ x1 + x2")
OLS: y ~ x1 + x2
Engines agree within tolerance (rtol=1e-08, atol=1e-10)

Coefficients
          python           r       stata      eviews
term
x1     0.4821094   0.4821094   0.4821094   0.4821094
x2    -0.1330277  -0.1330277  -0.1330277  -0.1330277
_cons  1.9042118   1.9042118   1.9042118   1.9042118

Notes:
  - aic: AIC normalisation differs: statsmodels -2ll+2k; R counts sigma^2 as a
    parameter (k+1); EViews divides by n; Stata needs `estat ic`.

The coefficients match. The information criteria do not — and EconEnv says why, instead of quietly picking one.


Architecture

graph TD
    A[JupyterLab / Notebook] --> B[IPython / Python kernel]
    B --> C[EconEnv extension]
    C --> D[Magics: %econ · %R · %stata · %eviews]
    C --> E[Engine registry]
    E --> F[Python engine]
    E --> G[R engine]
    E --> H[Stata engine]
    E --> I[EViews engine]
    G --> G1[subprocess backend<br/>persistent Rterm]
    G --> G2[rpy2 backend<br/>when installed]
    H --> H1[PyStata<br/>official]
    I --> I1[COM automation<br/>comtypes]
    C --> J[Data bridges<br/>pandas is canonical]
    C --> K[Results · Diagnostics · Snapshots]
    E -.future.-> L[MATLAB · Julia · SAS · Gretl · Dynare · GAUSS · Ox · RATS]

Three rules hold the design together:

  1. No custom kernel. EconEnv is a Python package plus an IPython extension. A polyglot kernel is evaluated in the roadmap, not assumed.
  2. Nothing above the engine layer touches a vendor API. Magics, the CLI, diagnostics and the model layer speak only to BaseEngine. Adding MATLAB means writing one adapter, not editing the core.
  3. Never hide a difference. Lossy conversions warn. Engine disagreements are reported with the defaults that explain them.

Features

Four engines, one kernel Python, R, Stata, EViews — persistent sessions, no kernel switching
Real data bridge pandas.DataFrame is canonical; push/pull/move between any two engines with no file round-trip
Type fidelity Factors, categoricals, dates, booleans, integers and missing values survive the trip — or you get a warning saying exactly what changed
Econometric metadata Time variable, panel variable, frequency, labels and conversion history travel with the frame
Structured results ExecutionResult and ModelResult instead of scraped text; raw engine output always retained
Cross-engine comparison Same specification, four engines, one table, with tolerance-aware agreement testing
Diagnostics econenv doctor checks every layer and tells you how to fix what is broken
Reproducibility Environment snapshots and provenance records (code hash, data hash, versions, timing)
Rich output HTML tables, PNG/SVG plots from R and EViews rendered inline
Honest about limits Capability matrix reports what each engine can do on this machine, not in theory

Installation

Released on PyPI: https://pypi.org/project/econenv/

pip install econenv

On an older release? Upgrade — EViews cell output and graph capture were broken in 0.1.0, and EViews version reporting in 0.1.0 and 0.1.1.

pip install --upgrade econenv

Optional extras — install only what you use:

pip install "econenv[stata]"    # helper for locating PyStata
pip install "econenv[eviews]"   # comtypes, Windows only
pip install "econenv[arrow]"    # fast Arrow transfer to R
pip install "econenv[all]"

Then, in a notebook:

%load_ext econenv
%econ doctor

Requirements

Required Notes
Python 3.9+ the host kernel
pandas, numpy, IPython, statsmodels yes installed automatically
R optional 4.0+; EconEnv finds it, no PATH setup needed
Stata optional 17 or newer — PyStata ships with Stata 17+
EViews optional Windows only; automation is COM-based
comtypes for EViews pip install "econenv[eviews]"
rpy2 never required no Windows wheels; EconEnv's subprocess backend replaces it

Engine setup

EconEnv discovers installations automatically — environment variables, PATH, the Windows registry, then the usual install roots. You should not need to configure anything. When you do:

%econ config r.home      "C:/Program Files/R/R-4.5.2"
%econ config stata.home  "C:/Program Files/Stata19"
%econ config stata.edition mp
%econ config eviews.progid EViews.Manager.14

Or persistently, in ~/.econenv/config.toml:

[r]
home = "C:/Program Files/R/R-4.5.2"

[stata]
home = "C:/Program Files/StataNow19"
edition = "mp"

[eviews]
progid = "EViews.Manager.14"

Environment variables work too: ECONENV_STATA_EDITION=mp, R_HOME, STATA_HOME.

A note on R and Windows. rpy2 publishes no Windows wheels, so EconEnv's default R backend is a persistent Rterm child process driven over a private protocol — no compiler, no R_HOME gymnastics. Where rpy2 is installed (usually Linux and macOS) EconEnv uses it, and loads rpy2's own %R/%%R magics rather than shadowing them.


Examples

Move data without touching a file

econenv.push("stata", "default", df)      # Python  → Stata
econenv.move("stata", "r", "default")     # Stata   → R
back = econenv.pull("r", "econenv_ols_data")

Keep the metadata

%%R -i panel -o results
library(plm)
fit <- plm(y ~ x, data = panel, index = c("id", "year"), model = "within")
results <- as.data.frame(summary(fit)$coefficients)

panel's MultiIndex is recognised as (entity, time); results comes back with its R types intact.

See what a transfer cost

econenv.push("eviews", "wf", df)
UserWarning: EconEnv push -> eviews: [warning] region: categorical stored as
integer codes; EViews has no factor type

Diagnose

econenv doctor
✔ PASS    Python: 3.11.0
✔ PASS    R installation: C:\Program Files\R\R-4.5.2 (R 4.5.2)
! WARNING Multiple R versions: 4.5.2, 4.4.3
              → EconEnv picks the newest. Pin one with `%econ config r.home ...`.
✔ PASS    PyStata: C:\Program Files\StataNow19\utilities\pystata
! WARNING COM version binding: several EViews versions are installed
              → Pin one: `%econ config eviews.progid EViews.Manager.14`.

More in examples/:

  1. Quick start
  2. Python + R
  3. Python + Stata
  4. Python + EViews
  5. All four engines
  6. The same OLS in four engines
  7. Data transfer and type fidelity
  8. Time series
  9. Panel data

Project status

v0.1 — alpha, released on PyPI. Execution, engine management, the data bridge, results, graphs, diagnostics, snapshots and cross-engine OLS comparison are implemented and tested. The API may still change before v1.0.

Releases

Version What changed
0.1.3 PyPI · notes EViews plotting views (x.line) now render; no duplicate or repeated figures
0.1.2 PyPI · notes Correct EViews ProgID discovery; stop guessing the EViews version before connecting
0.1.1 PyPI · notes EViews cell output and graph capture; honest engine reporting
0.1.0 PyPI · notes First release

Install the latest with pip install --upgrade econenv.

What is verified, and on what:

Verified
Python engine yes, in CI
R engine (subprocess) yes, against R 4.5.2 on Windows
Stata engine yes, against StataNow 19.5 MP + PyStata 0.1.2
EViews engine yes, against EViews 13 via COM on Windows
R engine (rpy2) not verified — no rpy2 on the development machine
Linux / macOS not verified — the design supports them; nobody has run them yet

Where something is untested, this README and the docs say so. See docs/audit/PHASE0_TECHNOLOGY_AUDIT.md for the measured evidence behind every technical decision.

Roadmap

Version Scope
v0.1 Execution + engine management + data bridge + results + graphs + diagnostics ✅
v0.2 Broader type coverage, Stata value labels, EViews alpha/matrix transfer, Arrow everywhere
v0.3 Model registry beyond OLS: logit, probit, IV, panel FE/RE
v0.4 Time-series and cointegration estimators; richer comparison reports
v0.5 Full provenance capture and run manifests
v1.0 Stable public API, documented multi-engine workflow, JupyterLab cell-toolbar extension

Graphs were pulled forward from v0.3 into v0.1: plot capture is a property of the transport layer, and retrofitting it later would have meant touching every adapter twice.


Platform support

Python R Stata EViews
Windows
Linux ✖ COM is unavailable
macOS ✖ COM is unavailable

The absence of EViews never blocks installation or use of the others. On non-Windows platforms the EViews engine reports itself unavailable and everything else works normally.


Commercial software disclaimer

EconEnv contains, bundles and redistributes no part of Stata or EViews — no binaries, no libraries, no licence files, no serial numbers, no activation keys.

EconEnv locates software already installed on your machine and drives it through each vendor's own documented automation interface. You are responsible for obtaining, installing and licensing Stata and EViews, and for complying with those licences, including any restriction on concurrent sessions, server deployment or automated use.

Stata® is a registered trademark of StataCorp LLC. EViews® is a registered trademark of IHS Global Inc. R is free software from the R Foundation. None of them endorses or is affiliated with this project.


Troubleshooting

Start with econenv doctor — it names the problem and the fix. Common ones are in docs/troubleshooting.md, including:

  • Stata says the edition is wrong
  • EViews connects to the wrong version
  • R starts but never becomes ready
  • pyeviews fails to import (it is not needed)
  • Values arrive in EViews as all-NA

Contributing

Issues and pull requests are welcome. See docs/development.md for the layout, the test markers (-m "not stata and not eviews" runs everything that needs no licence) and how to write a new engine adapter.

Citation

If EconEnv is part of your research workflow, please cite it — see CITATION.cff.

License

MIT — see LICENSE. The MIT grant covers EconEnv's own source only and confers no rights in Stata, EViews or R.

Author

Dr Merwan Roudane · github.com/merwanroudane

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

econenv-0.1.3.tar.gz (143.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

econenv-0.1.3-py3-none-any.whl (113.1 kB view details)

Uploaded Python 3

File details

Details for the file econenv-0.1.3.tar.gz.

File metadata

  • Download URL: econenv-0.1.3.tar.gz
  • Upload date:
  • Size: 143.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.0

File hashes

Hashes for econenv-0.1.3.tar.gz
Algorithm Hash digest
SHA256 3b2236fa7d3f62a4650b9f7163b11dcf19c457ecb7c1535da8017293c204e457
MD5 a0a4e8a0c6695dbc6ee741a8bf00f0c2
BLAKE2b-256 153d4c797661a42a1d0e456adb5e68a985dd3133e9e8421a4a752e404da74869

See more details on using hashes here.

File details

Details for the file econenv-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: econenv-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 113.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.0

File hashes

Hashes for econenv-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a0fe5de603e2fa1704d90511fccd5cd7dd14a82016f9e4bf26f598c952daeb6f
MD5 35f4a417ce114372c7c4a4117f7df218
BLAKE2b-256 5d31298b03145890bfb3f213e29f1f44e99289b90079b8900e1a6aee2d92375f

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.1

2 files

1.0.9

2 files

1.0.8

2 files

1.0.7

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page