pymetrix-eviews 0.1.0a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pymetrix_eviews/__init__.py +83 -0
- pymetrix_eviews/_version.py +1 -0
- pymetrix_eviews/app.py +374 -0
- pymetrix_eviews/bundle-1.schema.json +104 -0
- pymetrix_eviews/bundle.py +889 -0
- pymetrix_eviews/dates.py +196 -0
- pymetrix_eviews/export/pymetrix_export.prg +476 -0
- pymetrix_eviews/panel.py +326 -0
- pymetrix_eviews/program/__init__.py +292 -0
- pymetrix_eviews/program/control.py +1368 -0
- pymetrix_eviews/program/data.py +1479 -0
- pymetrix_eviews/program/estimation.py +1133 -0
- pymetrix_eviews/program/ir.py +395 -0
- pymetrix_eviews/program/left.py +89 -0
- pymetrix_eviews/program/models.py +462 -0
- pymetrix_eviews/program/parse.py +124 -0
- pymetrix_eviews/program/report.py +155 -0
- pymetrix_eviews/program/script.py +258 -0
- pymetrix_eviews/program/steps.py +234 -0
- pymetrix_eviews-0.1.0a1.dist-info/METADATA +248 -0
- pymetrix_eviews-0.1.0a1.dist-info/RECORD +24 -0
- pymetrix_eviews-0.1.0a1.dist-info/WHEEL +4 -0
- pymetrix_eviews-0.1.0a1.dist-info/entry_points.txt +8 -0
- pymetrix_eviews-0.1.0a1.dist-info/licenses/LICENSE +28 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""pymetrix-eviews: EViews work into pymetrix (docs/design/eviews-plugin.md).
|
|
2
|
+
|
|
3
|
+
This version reads EViews workfiles through a *bundle*: a folder that ``pymetrix_export.prg``, run once in the
|
|
4
|
+
user's own EViews, writes from the open workfile (each page's series as CSV, and a JSON manifest with the metadata,
|
|
5
|
+
groups, samples, scalars, matrices, equations and models). The binary ``.wf1`` is not read.
|
|
6
|
+
|
|
7
|
+
from pymetrix import Dataset
|
|
8
|
+
|
|
9
|
+
quarterly = Dataset.read("C:/work/macro-export/macro.evbundle", page="quarterly") # recorded, and replayed
|
|
10
|
+
annual = Dataset.read("C:/work/macro-export/macro.evbundle", page="annual")
|
|
11
|
+
|
|
12
|
+
from pymetrix_eviews import bundle_pages, compare_estimates, eviews_objects, save_export_program
|
|
13
|
+
bundle_pages("C:/work/macro-export/macro.evbundle") # the pages, their frequencies and series
|
|
14
|
+
eviews_objects(quarterly) # groups, samples, scalars, matrices and models
|
|
15
|
+
compare_estimates(quarterly) # least-squares equations refitted, against EViews's numbers
|
|
16
|
+
save_export_program("C:/work") # a copy of the export program
|
|
17
|
+
|
|
18
|
+
**The export program is experimental.** It was written from EViews's public documentation and has never been run in
|
|
19
|
+
EViews: the project has no EViews licence. Until someone with one has run it on the two most recent major versions,
|
|
20
|
+
saving the workfile from EViews as CSV or Excel, which pymetrix reads with File → Load data…, is the supported way
|
|
21
|
+
in. The reader is tested against bundles written by hand to the format, and the manifest's JSON Schema.
|
|
22
|
+
|
|
23
|
+
EViews programs (``.prg``) are translated into a readable script, a report with a row per line, and the same work as
|
|
24
|
+
recorded steps: data work, estimation, tests and models, and control flow (loops, ``if`` blocks, subroutines, included
|
|
25
|
+
programs, the program's arguments); what has no pymetrix equivalent is left out with the reason:
|
|
26
|
+
|
|
27
|
+
from pymetrix_eviews import translate_program
|
|
28
|
+
t = translate_program("C:/work/macro.prg", bundle="C:/work/macro-export/macro.evbundle")
|
|
29
|
+
print(t.script); t.report.summary(); t.run(session)
|
|
30
|
+
|
|
31
|
+
In the app: **File → Import EViews workfile…** (a workfile bundle, or a copy of the export program), **File → Translate
|
|
32
|
+
EViews program…** and the **EViews translation** panel (the report, the program beside the script, Run as steps).
|
|
33
|
+
Running EViews through COM is later work.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
from __future__ import annotations
|
|
37
|
+
|
|
38
|
+
from pymetrix.extension import PluginInfo
|
|
39
|
+
|
|
40
|
+
from ._version import __version__
|
|
41
|
+
|
|
42
|
+
PLUGIN = PluginInfo(
|
|
43
|
+
name="pymetrix-eviews",
|
|
44
|
+
version=__version__,
|
|
45
|
+
license="BSD-3-Clause",
|
|
46
|
+
maintainer="Geoffrey Heenan",
|
|
47
|
+
description="EViews workfiles into pymetrix through a bundle the (experimental) export program writes: pages, "
|
|
48
|
+
"series with their labels, groups, samples, scalars, matrices, equations and models",
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
from .bundle import ( # noqa: E402
|
|
52
|
+
FORMAT, FORMAT_VERSIONS, PROGRAM_VERSION, SUFFIX, EViewsBundleNote, bundle_model, bundle_pages, bundle_schema,
|
|
53
|
+
compare_estimates, eviews_objects, eviews_sample, export_program, read_bundle, save_export_program,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
from .program import ProgramTranslation, ReportRow, TranslationReport, translate_program # noqa: E402
|
|
57
|
+
|
|
58
|
+
_registered = False
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def register() -> None:
|
|
62
|
+
"""The entry point (``pymetrix.plugins``, ``pymetrix.io``, ``pymetrix.commands``): ``.evbundle`` files read
|
|
63
|
+
through ``read_bundle``, the File → Import EViews workfile… dialog and the help topic. Importing the package registers
|
|
64
|
+
them too; a second call does nothing."""
|
|
65
|
+
global _registered
|
|
66
|
+
if _registered:
|
|
67
|
+
return
|
|
68
|
+
_registered = True
|
|
69
|
+
from pymetrix.extension import plugin_context
|
|
70
|
+
from pymetrix.io.registry import register_reader
|
|
71
|
+
|
|
72
|
+
with plugin_context(PLUGIN):
|
|
73
|
+
register_reader(SUFFIX, read_bundle)
|
|
74
|
+
# imported outside the plugin's context: it imports pymetrix's own dialogs first, which must stay pymetrix's;
|
|
75
|
+
# it registers its dialog and help topic inside the context itself
|
|
76
|
+
from . import app # noqa: F401
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
register()
|
|
80
|
+
|
|
81
|
+
__all__ = ["FORMAT", "FORMAT_VERSIONS", "PLUGIN", "PROGRAM_VERSION", "SUFFIX", "EViewsBundleNote", "__version__", "bundle_model",
|
|
82
|
+
"bundle_pages", "bundle_schema", "compare_estimates", "eviews_objects", "eviews_sample", "export_program",
|
|
83
|
+
"read_bundle", "register", "save_export_program", "ProgramTranslation", "ReportRow", "TranslationReport", "translate_program"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0a1"
|
pymetrix_eviews/app.py
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
"""The plugin in the app: File → Import EViews workfile…, File → Translate EViews program…, the EViews translation
|
|
2
|
+
panel (``panel.py``) and the help topics, registered through the extension API."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import TYPE_CHECKING, Annotated, Any, ClassVar, Literal
|
|
9
|
+
|
|
10
|
+
from pymetrix.extension import Command, Widget, add_help_topic, command, plugin_context
|
|
11
|
+
|
|
12
|
+
from . import PLUGIN
|
|
13
|
+
from .bundle import SUFFIX, _py_name, bundle_pages, save_export_program
|
|
14
|
+
from .panel import create_panel
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from pymetrix.commands import Session
|
|
18
|
+
|
|
19
|
+
BUNDLE = "workfile bundle"
|
|
20
|
+
PROGRAM = "get the export program (experimental)"
|
|
21
|
+
_BUNDLE_ONLY = ("what", (BUNDLE,))
|
|
22
|
+
|
|
23
|
+
with plugin_context(PLUGIN):
|
|
24
|
+
@command(menu="File/Import EViews workfile...", id="eviews:import_eviews")
|
|
25
|
+
@dataclass(frozen=True)
|
|
26
|
+
class ImportEViews(Command):
|
|
27
|
+
"""Read an EViews workfile's pages through a bundle, or save a copy of the program that writes one.
|
|
28
|
+
|
|
29
|
+
A bundle is what the export program, pymetrix_export.prg, writes when it is run in EViews on an open workfile:
|
|
30
|
+
each page's series as CSV, and a manifest (.evbundle) with their labels and units, the groups, samples,
|
|
31
|
+
scalars, matrices, equations and models. Each page becomes a dataset named after it, read by one
|
|
32
|
+
Dataset.read(...) line in the script. Replaying the step needs this plugin; ticking Save the data as Parquet
|
|
33
|
+
writes each page next to the bundle as Parquet and reads it from there, so the script needs only pymetrix.
|
|
34
|
+
|
|
35
|
+
The export program is EXPERIMENTAL: it was written from EViews's documentation and has not been run in
|
|
36
|
+
EViews. Saving the workfile from EViews as CSV or Excel, and loading that with File > Load data, is the
|
|
37
|
+
supported way in until it has been checked; Get the export program saves a copy with every point to check
|
|
38
|
+
marked (verify).
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
topics: ClassVar[tuple[str, ...]] = ("eviews-import",)
|
|
42
|
+
|
|
43
|
+
what: Annotated[Literal["workfile bundle", "get the export program (experimental)"],
|
|
44
|
+
Widget("choice", label="Import",
|
|
45
|
+
help="a workfile bundle the export program wrote; or save a copy of that program "
|
|
46
|
+
"(experimental: untested in EViews)")] = BUNDLE
|
|
47
|
+
path: Annotated[str, Widget("file", source="EViews workfile bundles (*.evbundle);;All files (*)", show_if=_BUNDLE_ONLY,
|
|
48
|
+
label="Bundle", help="the bundle's manifest, <workfile>.evbundle, in the folder the "
|
|
49
|
+
"export program wrote")] = ""
|
|
50
|
+
pages: Annotated[str, Widget("text", show_if=_BUNDLE_ONLY,
|
|
51
|
+
help="the pages to read, separated by commas, as EViews names them; empty: every page")] = ""
|
|
52
|
+
parquet: Annotated[bool, Widget("checkbox", show_if=_BUNDLE_ONLY, label="Save the data as Parquet",
|
|
53
|
+
help="write each page next to the bundle as <page>.parquet and read it from there, "
|
|
54
|
+
"so replaying the script does not need this plugin")] = False
|
|
55
|
+
undated: Annotated[bool, Widget("checkbox", show_if=_BUNDLE_ONLY, advanced=True, label="Read dated pages as undated",
|
|
56
|
+
help="rows numbered from 1, the dates kept as text: for frequencies pandas has no "
|
|
57
|
+
"period for, such as semi-annual")] = False
|
|
58
|
+
save_to: Annotated[str, Widget("savefile", source="EViews programs (*.prg);;All files (*)", show_if=("what", (PROGRAM,)),
|
|
59
|
+
label="Save the program as",
|
|
60
|
+
help="where to save pymetrix_export.prg (experimental: untested in EViews)")] = ""
|
|
61
|
+
|
|
62
|
+
def _pages(self) -> list[str]:
|
|
63
|
+
chosen = [p.strip() for p in self.pages.split(",") if p.strip()]
|
|
64
|
+
return chosen or [p["name"] for p in bundle_pages(self.path)]
|
|
65
|
+
|
|
66
|
+
def _plan(self) -> list[tuple[str, str, str]]:
|
|
67
|
+
"""(page, the dataset's name, the Parquet copy's path) for each page read."""
|
|
68
|
+
folder = Path(self.path).parent
|
|
69
|
+
return [(page, _py_name(page), str(folder / f"{_py_name(page)}.parquet")) for page in self._pages()]
|
|
70
|
+
|
|
71
|
+
def validate(self, session: Session) -> list[str]:
|
|
72
|
+
from pymetrix.errors import PyMetrixError
|
|
73
|
+
|
|
74
|
+
if self.what == PROGRAM:
|
|
75
|
+
return [] if self.save_to.strip() else ["choose where to save the export program"]
|
|
76
|
+
if not self.path.strip():
|
|
77
|
+
return [f"choose the bundle ({SUFFIX}) the export program wrote"]
|
|
78
|
+
try:
|
|
79
|
+
known = {p["name"].lower(): p for p in bundle_pages(self.path)}
|
|
80
|
+
plan = self._plan()
|
|
81
|
+
except PyMetrixError as exc:
|
|
82
|
+
return [str(exc)]
|
|
83
|
+
errors = []
|
|
84
|
+
for page, _, _ in plan:
|
|
85
|
+
info = known.get(page.lower())
|
|
86
|
+
if info is None:
|
|
87
|
+
errors.append(f"the bundle has no page {page!r}; its pages: {', '.join(p['name'] for p in known.values())}")
|
|
88
|
+
elif info["refused"] and not self.undated:
|
|
89
|
+
errors.append(f"page {info['name']} ({info['frequency']}): {info['refused']}; tick Read dated pages as undated")
|
|
90
|
+
names = [name for _, name, _ in plan]
|
|
91
|
+
twice = sorted({n for n in names if names.count(n) > 1})
|
|
92
|
+
if twice:
|
|
93
|
+
errors.append(f"two pages would be called {', '.join(twice)}: read them one at a time")
|
|
94
|
+
return errors
|
|
95
|
+
|
|
96
|
+
def _calls(self) -> list[Any]:
|
|
97
|
+
from pymetrix.extension import make_call
|
|
98
|
+
|
|
99
|
+
options = {"undated": True} if self.undated else {}
|
|
100
|
+
if self.parquet:
|
|
101
|
+
return [make_call("pymetrix:dataset.read", output=name, recorded_by=self.command_id, source=copy)
|
|
102
|
+
for _, name, copy in self._plan()]
|
|
103
|
+
return [make_call("pymetrix:dataset.read", output=name, recorded_by=self.command_id, source=self.path, page=page, **options)
|
|
104
|
+
for page, name, _ in self._plan()]
|
|
105
|
+
|
|
106
|
+
def run(self, session: Session) -> Any:
|
|
107
|
+
from pymetrix.data import Dataset
|
|
108
|
+
|
|
109
|
+
if self.what == PROGRAM:
|
|
110
|
+
return save_export_program(self.save_to)
|
|
111
|
+
made = None
|
|
112
|
+
for (page, name, copy), call in zip(self._plan(), self._calls()):
|
|
113
|
+
if self.parquet and Path(self.path).is_file(): # the copy follows the bundle while the bundle is there
|
|
114
|
+
Dataset.read(self.path, page=page, **({"undated": True} if self.undated else {})).write(copy)
|
|
115
|
+
made = session.objects[name] = call.invoke(session.objects)
|
|
116
|
+
return made
|
|
117
|
+
|
|
118
|
+
def to_code(self) -> str:
|
|
119
|
+
if self.what == PROGRAM:
|
|
120
|
+
return f"from pymetrix_eviews import save_export_program\nsave_export_program({self.save_to!r})"
|
|
121
|
+
return "\n".join(call.to_code() for call in self._calls())
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
PROGRAMS = "EViews programs (*.prg);;All files (*)"
|
|
125
|
+
DATA = "Workfile data (*.evbundle *.csv *.xlsx *.xls);;All files (*)"
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
with plugin_context(PLUGIN):
|
|
129
|
+
@command(menu="File/Translate EViews program...", id="eviews:translate_program")
|
|
130
|
+
@dataclass(frozen=True)
|
|
131
|
+
class TranslateEViewsProgram(Command):
|
|
132
|
+
"""Translate an EViews program (.prg) into a readable pymetrix script and a report on every line.
|
|
133
|
+
|
|
134
|
+
The translation opens in the EViews translation panel: each line of the program with its status (translated,
|
|
135
|
+
translated with a note, left out, error) and the reason, the program and the script side by side, and Run as
|
|
136
|
+
steps, which makes the program's work steps of this session, each recorded and undoable. The step itself
|
|
137
|
+
only translates: it reads the program, keeps it, its script and its report in the project, and changes no
|
|
138
|
+
data.
|
|
139
|
+
|
|
140
|
+
Workfile data is what the program's wfopen opens: the bundle the export program wrote, or a CSV or Excel file
|
|
141
|
+
saved from the workfile in EViews (give its date column and frequency). The program's arguments are what
|
|
142
|
+
follows its name in EViews's exec (exec macro.prg us 2020q1): they become %0, %1, ..., the script's
|
|
143
|
+
parameters.
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
topics: ClassVar[tuple[str, ...]] = ("eviews-programs",)
|
|
147
|
+
|
|
148
|
+
path: Annotated[str, Widget("file", source=PROGRAMS, label="Program", help="the EViews program to translate (.prg); "
|
|
149
|
+
"programs it includes are read from its folder")] = ""
|
|
150
|
+
data: Annotated[str, Widget("file", source=DATA, label="Workfile data",
|
|
151
|
+
help="what the program's wfopen opens: the bundle the export program wrote, or a CSV or "
|
|
152
|
+
"Excel file saved from the workfile in EViews; empty for a program that makes its "
|
|
153
|
+
"own pages (wfcreate)")] = ""
|
|
154
|
+
time: Annotated[str, Widget("text", label="Date column", help="a CSV or Excel file's column of dates (obs, say); "
|
|
155
|
+
"empty: as Load data finds it")] = ""
|
|
156
|
+
freq: Annotated[Literal["", "Y", "Q", "M", "W", "D"], Widget("choice", label="Frequency",
|
|
157
|
+
help="the dates' frequency in a CSV or Excel file: Y "
|
|
158
|
+
"annual, Q quarterly, M monthly, W weekly, D "
|
|
159
|
+
"daily; empty: as Load data finds it")] = ""
|
|
160
|
+
args: Annotated[str, Widget("text", label="Program arguments",
|
|
161
|
+
help="what follows the program's name in EViews's exec, separated by spaces: %0, %1, "
|
|
162
|
+
"..., the script's parameters (arg0, arg1)")] = ""
|
|
163
|
+
|
|
164
|
+
def options(self) -> dict[str, Any]:
|
|
165
|
+
"""translate_program's keyword arguments."""
|
|
166
|
+
out: dict[str, Any] = {}
|
|
167
|
+
if self.data.strip():
|
|
168
|
+
out["bundle"] = self.data.strip()
|
|
169
|
+
read = {k: v for k, v in (("time", self.time.strip()), ("freq", self.freq)) if v}
|
|
170
|
+
if read and not self.data.strip().lower().endswith(".evbundle"):
|
|
171
|
+
out["read_options"] = read
|
|
172
|
+
if self.args.strip():
|
|
173
|
+
out["args"] = " ".join(self.args.split())
|
|
174
|
+
return out
|
|
175
|
+
|
|
176
|
+
def validate(self, session: Session) -> list[str]:
|
|
177
|
+
if not self.path.strip():
|
|
178
|
+
return ["choose the EViews program (.prg) to translate"]
|
|
179
|
+
if not Path(self.path).is_file():
|
|
180
|
+
return [f"there is no program {self.path}"]
|
|
181
|
+
if self.data.strip() and not Path(self.data.strip()).is_file():
|
|
182
|
+
return [f"there is no file {self.data.strip()}: the bundle the export program wrote, or a CSV or Excel file"]
|
|
183
|
+
return []
|
|
184
|
+
|
|
185
|
+
def translate(self) -> Any:
|
|
186
|
+
from .program import translate_program
|
|
187
|
+
|
|
188
|
+
return translate_program(self.path, **self.options())
|
|
189
|
+
|
|
190
|
+
def run(self, session: Session) -> Any:
|
|
191
|
+
translation = self.translate()
|
|
192
|
+
_TRANSLATIONS[_key(self)] = translation
|
|
193
|
+
files = session.attachments.setdefault("pymetrix-eviews", {})
|
|
194
|
+
stem = Path(self.path).stem
|
|
195
|
+
for name, text in translation.sources.items():
|
|
196
|
+
files[f"{stem}/{name}"] = text.encode("utf-8") # the program as translated: the panel's copy if it moves
|
|
197
|
+
files[f"{stem}.py"] = translation.script.encode("utf-8")
|
|
198
|
+
files[f"{stem}.txt"] = translation.report.to_text().encode("utf-8")
|
|
199
|
+
return translation
|
|
200
|
+
|
|
201
|
+
def to_code(self) -> str:
|
|
202
|
+
options = "".join(f", {k}={v!r}" for k, v in self.options().items())
|
|
203
|
+
return (f"from pymetrix_eviews import translate_program\n"
|
|
204
|
+
f"{_py_name(Path(self.path).stem)}_translation = translate_program({self.path!r}{options})")
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
_TRANSLATIONS: dict[tuple[Any, ...], Any] = {} # the translations made, by their step's fields (the panel's)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _key(cmd: Any) -> tuple[Any, ...]:
|
|
211
|
+
return (cmd.path, cmd.data, cmd.time, cmd.freq, cmd.args)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def translation_of(session: Any, cmd: Any) -> Any:
|
|
215
|
+
"""The translation a step made: kept from the step, or made again (from the program the project keeps, when the
|
|
216
|
+
file is no longer there)."""
|
|
217
|
+
key = _key(cmd)
|
|
218
|
+
if key not in _TRANSLATIONS:
|
|
219
|
+
from .program import translate_program
|
|
220
|
+
|
|
221
|
+
if Path(cmd.path).is_file():
|
|
222
|
+
_TRANSLATIONS[key] = cmd.translate()
|
|
223
|
+
else:
|
|
224
|
+
kept = session.attachments.get("pymetrix-eviews", {}).get(f"{Path(cmd.path).stem}/{Path(cmd.path).name}")
|
|
225
|
+
if kept is None:
|
|
226
|
+
return None
|
|
227
|
+
options = cmd.options()
|
|
228
|
+
_TRANSLATIONS[key] = translate_program(kept.decode("utf-8"), folder=Path(cmd.path).parent, **options)
|
|
229
|
+
return _TRANSLATIONS[key]
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def translations(session: Any) -> list[tuple[Any, Any]]:
|
|
233
|
+
"""The session's translations, from its History's Translate EViews program steps: (step, translation)."""
|
|
234
|
+
out = []
|
|
235
|
+
for record in getattr(session, "history", []):
|
|
236
|
+
cmd = getattr(record, "command", None)
|
|
237
|
+
if isinstance(cmd, TranslateEViewsProgram):
|
|
238
|
+
t = translation_of(session, cmd)
|
|
239
|
+
if t is not None:
|
|
240
|
+
out.append((cmd, t))
|
|
241
|
+
return out
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _help() -> None:
|
|
245
|
+
add_help_topic("eviews-import", "EViews workfiles (the pymetrix-eviews plugin)", """
|
|
246
|
+
pymetrix does not read EViews's binary workfiles (.wf1): their format is not published, and a misread column
|
|
247
|
+
of numbers looks like data. There are two ways in.
|
|
248
|
+
|
|
249
|
+
**Supported: save from EViews as CSV or Excel.** In EViews, save the page (File > Save As, or
|
|
250
|
+
wfsave(type=...)) as CSV or Excel, then File > Load data in pymetrix, with the date column as Time and the
|
|
251
|
+
page's frequency. Labels and other metadata do not come with it.
|
|
252
|
+
|
|
253
|
+
**Experimental: the export program.** File > Import EViews workfile > Get the export program saves
|
|
254
|
+
pymetrix_export.prg. In EViews, open the workfile and run it: exec pymetrix_export.prg C:\\work\\macro-export.
|
|
255
|
+
It writes a bundle: each page's series as CSV, with the series' labels, units and sources, the groups,
|
|
256
|
+
samples, scalars, strings, vectors and matrices, value maps, equations (with EViews's estimates) and models,
|
|
257
|
+
and a manifest, <workfile>.evbundle, which File > Import EViews workfile (Workfile bundle) reads. The program was
|
|
258
|
+
written from EViews's documentation and has NOT been run in EViews: the project has no licence. Every point
|
|
259
|
+
to check is marked (verify) in it. If it fails, or its bundle is refused, use CSV or Excel and report what
|
|
260
|
+
happened.
|
|
261
|
+
|
|
262
|
+
Each page becomes a dataset named after it, read by Dataset.read(path, page=...), so replaying needs the
|
|
263
|
+
plugin; Save the data as Parquet reads each page from a Parquet copy instead, so the script needs only
|
|
264
|
+
pymetrix. In code, eviews_objects(data) gives the page's groups (as selections), samples, scalars, matrices
|
|
265
|
+
and models (read by read_eviews); compare_estimates(data) refits each least-squares equation and sets
|
|
266
|
+
pymetrix's estimates beside EViews's, saying where they match.
|
|
267
|
+
|
|
268
|
+
What is refused, with its place: a folder without its manifest (an incomplete export), a bundle of a newer
|
|
269
|
+
format version (update pymetrix-eviews), a CSV without a column the manifest lists, and pages of a frequency
|
|
270
|
+
pandas has no period for (semi-annual, multi-year, intraday): those read as undated. Value maps are kept in
|
|
271
|
+
each series' metadata (Variable.extra) but are not labels of its values: pymetrix has no value labels yet.
|
|
272
|
+
|
|
273
|
+
EViews programs (.prg) are translated with File > Translate EViews program, or in code with
|
|
274
|
+
translate_program: see the topic on EViews programs.
|
|
275
|
+
""", see_also=("eviews-programs",))
|
|
276
|
+
add_help_topic("eviews-programs", "EViews programs (the pymetrix-eviews plugin)", """
|
|
277
|
+
File > Translate EViews program asks for the program, the workfile data its wfopen opens (the bundle, or a
|
|
278
|
+
CSV or Excel file saved from EViews, with its date column and frequency) and the program's arguments (%0,
|
|
279
|
+
%1). The translation opens in the EViews translation panel (View > EViews translation): a row for each line,
|
|
280
|
+
its status in words and in colour, the reason; the program and the script side by side, both following the
|
|
281
|
+
row selected; a filter for each status, with its count; Copy (the selected rows, or the whole report) and
|
|
282
|
+
Copy script; and Run as steps, which runs the program's work in this session one step at a time, each
|
|
283
|
+
recorded and undoable, stopping at the first step that fails and marking its row.
|
|
284
|
+
|
|
285
|
+
In code, translate_program turns an EViews program (.prg) into three things, from one reading of it:
|
|
286
|
+
|
|
287
|
+
from pymetrix_eviews import translate_program
|
|
288
|
+
t = translate_program("macro.prg", bundle="macro-export/macro.evbundle")
|
|
289
|
+
print(t.script) # Python, each EViews line as a comment above what it became
|
|
290
|
+
t.report.summary() # a row per line, with its status and the reason
|
|
291
|
+
t.run(session) # the same work as steps, recorded in the session's History
|
|
292
|
+
|
|
293
|
+
The script uses pymetrix's public API only, and reads like the program. Running it, or running the steps,
|
|
294
|
+
gives the same datasets and values. The steps are recorded as if made in dialogs; the script and the
|
|
295
|
+
report are kept in the project.
|
|
296
|
+
|
|
297
|
+
**What the statuses mean.** Translated: the line became the Python shown. Translated with a note: it did,
|
|
298
|
+
and the note says something to know (a name changed, a value put in, a formula worked out period by
|
|
299
|
+
period). Left out: the line is not translated, and the reason says why and what to use in pymetrix.
|
|
300
|
+
Error: the line does not read, or names something the program has not made. Every line with text has a
|
|
301
|
+
row: nothing is dropped silently.
|
|
302
|
+
|
|
303
|
+
**What is translated (phase 1, data work).** wfopen (of the bundle the export program wrote, or of a CSV
|
|
304
|
+
or Excel file saved from the workfile, given as bundle=), wfcreate and pagecreate, pageselect; smpl and
|
|
305
|
+
sample, with dates, @first and @last, offsets, if conditions and named samples; series, genr and plain
|
|
306
|
+
assignments, within the current sample; frml as a derived series; group; label, displayname and setattr;
|
|
307
|
+
rename, delete and fill; scalars, !numbers and %strings as Python variables, with {%s} and {!i} put in where
|
|
308
|
+
their value is known before the program runs; @mean, @sum, @min, @max, @stdev, @median and @obs as a
|
|
309
|
+
scalar's value over the sample; vectors and matrices.
|
|
310
|
+
|
|
311
|
+
**What is translated (phase 2, estimation, tests and models).** Equations by ls (with cov=white or hac, and
|
|
312
|
+
ar and ma terms), tsls, gmm, liml, arch, binary, ordered, censored, count, qreg, heckit and ardl, each a
|
|
313
|
+
fitted Equation (or ARDL), with the options that map; list specifications (y c x y(-1) becomes y ~ x +
|
|
314
|
+
y[-1]) and expression specifications (y = c(1) + c(2)*x, with parameters c_1, c_2). Each estimate keeps
|
|
315
|
+
its coefficient map, EViews's c(i) against pymetrix's coefficient, which later lines use: eq.@coefs(2),
|
|
316
|
+
@stderrs, @tstats, @r2, @se, @dw, @regobs, @aic (per observation, as EViews), and c(2) after an
|
|
317
|
+
estimation. VARs (var v.ls 1 4 y1 y2 @ c) and VECs (v.ec); systems (sur, 3sls, fiml, tsls); wald,
|
|
318
|
+
testdrop, auto, hettest, archtest, reset, chow, hist and rls; uroot (adf, pp, kpss, dfgls, ers, np) and
|
|
319
|
+
coint; forecast, fit and makeresids, the series added to the page. Models: model, append, merge,
|
|
320
|
+
@identity, @add and @innov collected into one text, read by read_eviews before the model is used (its
|
|
321
|
+
refusals in the report at their lines); solve and solveopt, addassign and addinit (Model.add_factors),
|
|
322
|
+
scenarios, override and exclude, the solution's series added to the page under the scenario's alias
|
|
323
|
+
(y_0, y_1).
|
|
324
|
+
|
|
325
|
+
Where EViews's defaults differ from pymetrix's (the HAC bandwidth, the ARMA and GARCH estimators, the
|
|
326
|
+
default solver), the line is translated with a note saying what to check. An option that is not mapped
|
|
327
|
+
leaves the line out, naming it: an estimate that ran without it would differ without saying so.
|
|
328
|
+
|
|
329
|
+
**What is translated (phase 3, control flow).** for !i = 1 to n step k, for %s a b c, while ... wend, and
|
|
330
|
+
if ... else ... endif stay loops and ifs in the script; exitloop, return and stop become break, return and
|
|
331
|
+
the end of the program. Subroutines become functions, defined at the top of the script, with string and
|
|
332
|
+
scalar parameters; EViews passes arguments by reference, so a parameter the subroutine assigns goes back to
|
|
333
|
+
the caller's variable; a local subroutine shares none of the program's names (its data and estimation
|
|
334
|
+
lines are left out, as EViews deletes what it makes). include translates the included program in line,
|
|
335
|
+
its rows under its name. {%s} and {!i} with a value known only as the program runs make the name then (an
|
|
336
|
+
f-string in the script). Conditions read the program's strings and numbers, @word, @wcount, @wfind,
|
|
337
|
+
@wlookup, @isobject, @lower, @replace, @mid and the other string functions, a group's @count and
|
|
338
|
+
@seriesname, the sample's statistics, and an equation's @r2 and other values, so "if eq.@r2 > 0.5" is
|
|
339
|
+
decided by the equation just estimated. The program's arguments (%0, %1) are the script's parameters
|
|
340
|
+
(arg0, arg1). Run as steps, the loops and conditions run in Python and only the steps are recorded, each
|
|
341
|
+
one undoable; a while loop stops after 10,000 passes.
|
|
342
|
+
|
|
343
|
+
**What is left out.** stepls, breakls, threshold, switchreg, glm and nls (each naming pymetrix's
|
|
344
|
+
equivalent); testadd and the extreme-value link (gaps); graphs, tables, spools and display; EViews
|
|
345
|
+
databases (fetch and store); add-ins (what they make can be given to translate_program as objects=);
|
|
346
|
+
subroutine parameters that are objects; names with $ in them; and the expression functions pymetrix has no
|
|
347
|
+
equivalent of: @date, @trend, @seas and @elem in data work, @obssmpl inside a series' formula, @strdate,
|
|
348
|
+
and @sumsby and the like grouped by anything but a series' name (docs/known-gaps.md in pymetrix lists them).
|
|
349
|
+
|
|
350
|
+
**Expression functions.** @log10, @floor, @ceiling, @round, @isna, @nan, @iif (and @recode), na, @year,
|
|
351
|
+
@quarter, @month, @day, @obsnum, @obsid, @cumsum, @sumsby, @meansby, @minsby and @maxsby translate to
|
|
352
|
+
pymetrix's functions (log10, floor, ceil, round, isna, fillna, iif, na, year(), ..., obsnum(), cumsum, sum(x,
|
|
353
|
+
by=g) ...). pymetrix computes @cumsum and the by-group statistics over all the page's rows, EViews over the
|
|
354
|
+
current sample: a line under a smpl says so. Random numbers (nrnd, rnd, @rnorm, @runif) become normrnd and
|
|
355
|
+
unifrnd with a seed: rndseed n gives the draws after it n*1000 + 1, n*1000 + 2 ..., and without a rndseed
|
|
356
|
+
the program's draws are seeded 1, 2 ... in order. pymetrix's numbers are never EViews's, so each such line is
|
|
357
|
+
translated with a note "to check".
|
|
358
|
+
|
|
359
|
+
**EViews's dates.** @dateval, @datestr (with a format), @dateadd, @datediff, @dtoo and @otod act on the
|
|
360
|
+
program's strings and numbers, so they are worked out as Python values, with EViews's date numbers (days
|
|
361
|
+
since 1 January A.D. 1, that day 0): now, when the values are known before the program runs, else when the
|
|
362
|
+
script runs (it imports pymetrix_eviews.dates). FRB/US's dateshift subroutine translates as it is.
|
|
363
|
+
|
|
364
|
+
A program's wfopen needs the workfile's data: export it with the export program (experimental), or save it
|
|
365
|
+
from EViews as CSV or Excel and pass that file, with read_options={"time": "obs", "freq": "Q"} for
|
|
366
|
+
Dataset.read.
|
|
367
|
+
""", see_also=("eviews-import",))
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
with plugin_context(PLUGIN):
|
|
371
|
+
_help()
|
|
372
|
+
from pymetrix.extension import AppPanel, register as _add
|
|
373
|
+
|
|
374
|
+
_add("panels", AppPanel("EViews translation", create_panel, area="bottom"), name="eviews_translation") # View → EViews translation
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/GeoffHeenan/pymetrix/packages/pymetrix-eviews/bundle-1.schema.json",
|
|
4
|
+
"title": "pymetrix EViews bundle manifest, format version 1",
|
|
5
|
+
"description": "The manifest (.evbundle) that pymetrix_export.prg writes. Within version 1 changes are additive: readers keep and note keys they do not know, so objects allow other properties.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["format", "format_version", "exporter", "workfile", "pages"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"format": {"const": "pymetrix-eviews-bundle"},
|
|
10
|
+
"format_version": {"const": 1},
|
|
11
|
+
"exporter": {
|
|
12
|
+
"type": "object",
|
|
13
|
+
"required": ["program_version"],
|
|
14
|
+
"properties": {
|
|
15
|
+
"program_version": {"type": "string", "pattern": "^[0-9]+(\\.[0-9]+)*$"},
|
|
16
|
+
"eviews_version": {"type": "string"},
|
|
17
|
+
"exported": {"type": "string"}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"workfile": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"required": ["name"],
|
|
23
|
+
"properties": {
|
|
24
|
+
"name": {"type": "string", "minLength": 1},
|
|
25
|
+
"path": {"type": "string"},
|
|
26
|
+
"active_page": {"type": "string"}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"na": {"type": "string", "minLength": 1},
|
|
30
|
+
"pages": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/page"}}
|
|
31
|
+
},
|
|
32
|
+
"$defs": {
|
|
33
|
+
"name": {"type": "string", "minLength": 1},
|
|
34
|
+
"file": {"type": "string", "minLength": 1, "pattern": "^(?![/\\\\])(?![A-Za-z]:)(?!.*(^|[/\\\\])\\.\\.([/\\\\]|$)).+$"},
|
|
35
|
+
"page": {
|
|
36
|
+
"type": "object",
|
|
37
|
+
"required": ["name", "structure", "file", "series"],
|
|
38
|
+
"properties": {
|
|
39
|
+
"name": {"$ref": "#/$defs/name"},
|
|
40
|
+
"structure": {"enum": ["dated", "undated", "panel"]},
|
|
41
|
+
"frequency": {"type": "string"},
|
|
42
|
+
"range": {"type": "array", "items": {"type": "string"}, "minItems": 2, "maxItems": 2},
|
|
43
|
+
"sample": {"type": "string"},
|
|
44
|
+
"file": {"$ref": "#/$defs/file"},
|
|
45
|
+
"date_column": {"type": ["string", "null"]},
|
|
46
|
+
"id_columns": {"type": "array", "items": {"$ref": "#/$defs/name"}},
|
|
47
|
+
"series": {"type": "array", "items": {"$ref": "#/$defs/series"}},
|
|
48
|
+
"groups": {"type": "array", "items": {
|
|
49
|
+
"type": "object", "required": ["name", "members"],
|
|
50
|
+
"properties": {"name": {"$ref": "#/$defs/name"}, "members": {"type": "array", "items": {"type": "string"}}}}},
|
|
51
|
+
"samples": {"type": "array", "items": {
|
|
52
|
+
"type": "object", "required": ["name", "text"],
|
|
53
|
+
"properties": {"name": {"$ref": "#/$defs/name"}, "text": {"type": "string"}}}},
|
|
54
|
+
"scalars": {"type": "array", "items": {
|
|
55
|
+
"type": "object", "required": ["name", "value"],
|
|
56
|
+
"properties": {"name": {"$ref": "#/$defs/name"}, "value": {"type": ["number", "null"]}}}},
|
|
57
|
+
"strings": {"type": "array", "items": {
|
|
58
|
+
"type": "object", "required": ["name", "value"],
|
|
59
|
+
"properties": {"name": {"$ref": "#/$defs/name"}, "value": {"type": "string"}}}},
|
|
60
|
+
"arrays": {"type": "array", "items": {
|
|
61
|
+
"type": "object", "required": ["name", "type", "rows", "cols", "file"],
|
|
62
|
+
"properties": {"name": {"$ref": "#/$defs/name"}, "type": {"enum": ["vector", "rowvector", "matrix", "sym", "coef"]},
|
|
63
|
+
"rows": {"type": "integer", "minimum": 0}, "cols": {"type": "integer", "minimum": 0},
|
|
64
|
+
"file": {"$ref": "#/$defs/file"}}}},
|
|
65
|
+
"value_maps": {"type": "array", "items": {
|
|
66
|
+
"type": "object", "required": ["name", "file"],
|
|
67
|
+
"properties": {"name": {"$ref": "#/$defs/name"}, "file": {"$ref": "#/$defs/file"}}}},
|
|
68
|
+
"equations": {"type": "array", "items": {
|
|
69
|
+
"type": "object", "required": ["name", "method"],
|
|
70
|
+
"oneOf": [{"required": ["command"]}, {"required": ["command_file"]}],
|
|
71
|
+
"properties": {"name": {"$ref": "#/$defs/name"}, "command": {"type": "string"}, "command_file": {"$ref": "#/$defs/file"},
|
|
72
|
+
"method": {"type": "string"}, "sample": {"type": "string"},
|
|
73
|
+
"ncoef": {"type": "integer", "minimum": 0}, "estimates": {"$ref": "#/$defs/file"}}}},
|
|
74
|
+
"models": {"type": "array", "items": {
|
|
75
|
+
"type": "object", "required": ["name", "text"],
|
|
76
|
+
"properties": {"name": {"$ref": "#/$defs/name"}, "text": {"$ref": "#/$defs/file"}}}},
|
|
77
|
+
"skipped": {"type": "array", "items": {
|
|
78
|
+
"type": "object", "required": ["name", "type"],
|
|
79
|
+
"properties": {"name": {"type": "string"}, "type": {"type": "string"}, "reason": {"type": "string"}}}}
|
|
80
|
+
},
|
|
81
|
+
"allOf": [
|
|
82
|
+
{"if": {"properties": {"structure": {"enum": ["dated", "panel"]}}},
|
|
83
|
+
"then": {"required": ["frequency", "date_column"], "properties": {"date_column": {"type": "string", "minLength": 1}}}},
|
|
84
|
+
{"if": {"properties": {"structure": {"const": "panel"}}},
|
|
85
|
+
"then": {"required": ["id_columns"], "properties": {"id_columns": {"minItems": 1}}}}
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
"series": {
|
|
89
|
+
"type": "object",
|
|
90
|
+
"required": ["name", "kind"],
|
|
91
|
+
"properties": {
|
|
92
|
+
"name": {"$ref": "#/$defs/name"},
|
|
93
|
+
"kind": {"enum": ["numeric", "alpha"]},
|
|
94
|
+
"display_name": {"type": "string"},
|
|
95
|
+
"description": {"type": "string"},
|
|
96
|
+
"units": {"type": "string"},
|
|
97
|
+
"source": {"type": "string"},
|
|
98
|
+
"remarks": {"type": "string"},
|
|
99
|
+
"attributes": {"type": "object", "additionalProperties": {"type": "string"}},
|
|
100
|
+
"value_map": {"type": ["string", "null"]}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|