Menu

Tree [ba56a3] master /
 History

HTTPS access


File Date Author Commit
 demo 10 hours ago marcingretl marcingretl [93dfb1] GretlDataset methods: ::corr() and ::cov(), gre...
 doc 2025-08-20 marcingretl marcingretl [8752be] small code cleanups + some doc updates
 gretl 1 day ago marcingretl marcingretl [a1cd56] ::adj_rsq() method + some code cleanups
 src 10 hours ago marcingretl marcingretl [ba56a3] MS SDK small tweak
 .gitignore 2025-05-16 marcingretl marcingretl [d40554] version which builds whl (wheel) package for ms...
 LICENSE 2025-06-07 marcingretl marcingretl [104090] add licence
 MANIFEST.in 2025-05-22 marcingretl marcingretl [b5dde6] make examples fully usable (run_example() funct...
 README.md 2025-07-10 marcingretl marcingretl [15549f] fix for loading package in virtual env
 changelog.txt 10 hours ago marcingretl marcingretl [93dfb1] GretlDataset methods: ::corr() and ::cov(), gre...
 install.py 2025-05-22 marcingretl marcingretl [b5dde6] make examples fully usable (run_example() funct...
 meson.build 2025-07-29 marcingretl marcingretl [0119f7] preparation for windows/aarch64 support
 meson_options.txt 2025-05-17 marcingretl marcingretl [5523df] teaks to meson.build to install in local dirs b...
 pyproject.toml 2025-07-12 marcingretl marcingretl [eb89f2] bump version
 read.me 2025-07-29 Allin Cottrell Allin Cottrell [6d19ce] call gretl_set_python_mode() to get data file s...
 setup.py 2025-06-13 marcingretl marcingretl [8cb169] 'lagselect' switched off for VARs + bump versio...
 todo.txt 2025-06-24 marcingretl marcingretl [5ebdc4] fix for memory leaks related with user's variables
 webinstall.py 2025-07-12 marcingretl marcingretl [eb89f2] bump version

Read Me

gretl4py: Python Bindings for gretl

This package provides Python bindings to the gretl econometrics library via its official C API.

For full documentation, please visit the gretl4py project page <https://gretl.sourceforge.net/gretl4py.html>_.

.. note::

The official PDF documentation is still under development and requires updates and enhancements.

You can find useful example scripts in the demo/ subdirectory (view on SourceForge <https://sourceforge.net/p/gretl/gretl4py/ci/v0.2/tree/demo/>_).

Package Contents

  1. libgretl (including plugins) and its dependencies
  2. gretl4py binary module bridging Python with libgretl via its official API
  3. Python extensions supporting the binary module
  4. Example Python scripts in the examples/ directory
  5. Sample datasets in the data/ directory

Provided Functionality

Available Estimators:

::

ar, ar1, arima, biprobit, dpanel, duration, garch, heckit, hsk,
intreg, lad, logit, logistic, midasreg, mpols, negbin, ols, panel,
poisson, probit, quantreg, tobit, tsls, wls, var, vecm

Available Tests:

::

add, adf, arch, autocorr, bds, bkw, breusch-pagan, chow, coeffsum, coint, comfac,
cusum, difftest, johansen, kpss, leverage, levinlin, logs, meantest, normality,
normtest, omit, panel, panspec, qlrtest, reset, restrict, runs, squares,
white, white-nocross, vartest, vif, xdepend

.. note::

Some tests are dataset-based, while others are model-based.

Usage

  1. Loading Datasets
    ~~~~~~~~~~~~~~~~~~~

Supported formats: .gdt, .gdtb, .csv, .dta, .wf1, .xls, .xlsx, .ods

Use get_data() to load a dataset:

.. code-block:: python

import importlib.resources as resources
import gretl

data_dir = resources.files('gretl').joinpath('data')
d1 = gretl.get_data(str(data_dir.joinpath('bjg.gdt')))

.. note::

The first dataset loaded is automatically set as the default.

Bundled Datasets:

::

abdata.gdt, bjg.gdt, data9-7.gdt, greene19_1.gdt, grunfeld.gdt, mroz87.gdt,
rac3d.gdt, b-g.gdt, data4-10.gdt, denmark.gdt, greene22_2.gdt, kennan.gdt,
ooballot.gdt, tobit.gdt, bjg.csv, data4-1.gdt, gdp_midas.gdt, greene25_1.gdt,
longley.csv, penngrow.gdt, wtp.gdt

  1. Estimating Models
    ~~~~~~~~~~~~~~~~~~~~

Basic usage pattern:

.. code-block:: python

m = gretl.ESTIMATOR()
m.fit()

To pass a dataset explicitly, use the data=... keyword argument.

Example: OLS Regression

.. code-block:: python

m1 = gretl.ols(formula='g ~ const + lg').fit()
print(m1)

Examples

Example scripts are located in examples/estimators/ and include:

::

ar1.py, biprobit.py, heckit.py, logit.py, ols.py, probit.py, wls.py,
arima.py, duration.py, lad.py, mpols.py, panel.py, tobit.py, ar.py,
garch.py, logistic.py, negbin.py, poisson.py, quantreg.py, tsls.py

To view the source of ols.py:

.. code-block:: python

import inspect
import gretl.examples.estimators.ols

print(inspect.getsource(gretl.examples.estimators.ols.run_example))

To run the example:

.. code-block:: python

import gretl.examples.estimators.ols

gretl.examples.estimators.ols.run_example()

API Overview

class _gretl.Dataset
~~~~~~~~~~~~~~~~~~~~~~~~

Attributes:

  • is_default
  • source

Methods:

::

copy, repr, bwfilt, bkfilt, get_accessor, get_id, get_series,
hpfilt, linked_models_list, new_list, new_series, print, sample,
setobs, set_as_default, test, to_dict, to_file, varnames

class _gretl.Model
~~~~~~~~~~~~~~~~~~~~~~

Methods:

::

fcast, fit, get_accessor, get_formula

class _gretl.Model_NSE
~~~~~~~~~~~~~~~~~~~~~~~~~~

Methods:

::

restrict, test

class _gretl.Model_GretlModel_VAR
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Methods:

::

irf, test

class _gretl.GretlModel_VAR_VECM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Methods:

::

restrict

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.