pymetrix-eviews 0.1.0a1__tar.gz

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.
Files changed (63) hide show
  1. pymetrix_eviews-0.1.0a1/.gitignore +10 -0
  2. pymetrix_eviews-0.1.0a1/LICENSE +28 -0
  3. pymetrix_eviews-0.1.0a1/PKG-INFO +248 -0
  4. pymetrix_eviews-0.1.0a1/README.md +230 -0
  5. pymetrix_eviews-0.1.0a1/pyproject.toml +37 -0
  6. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/__init__.py +83 -0
  7. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/_version.py +1 -0
  8. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/app.py +374 -0
  9. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/bundle-1.schema.json +104 -0
  10. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/bundle.py +889 -0
  11. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/dates.py +196 -0
  12. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/export/pymetrix_export.prg +476 -0
  13. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/panel.py +326 -0
  14. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/program/__init__.py +292 -0
  15. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/program/control.py +1368 -0
  16. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/program/data.py +1479 -0
  17. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/program/estimation.py +1133 -0
  18. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/program/ir.py +395 -0
  19. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/program/left.py +89 -0
  20. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/program/models.py +462 -0
  21. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/program/parse.py +124 -0
  22. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/program/report.py +155 -0
  23. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/program/script.py +258 -0
  24. pymetrix_eviews-0.1.0a1/src/pymetrix_eviews/program/steps.py +234 -0
  25. pymetrix_eviews-0.1.0a1/tests/conftest.py +5 -0
  26. pymetrix_eviews-0.1.0a1/tests/fixtures/.gitattributes +2 -0
  27. pymetrix_eviews-0.1.0a1/tests/fixtures/command_ids.json +5 -0
  28. pymetrix_eviews-0.1.0a1/tests/fixtures/cp1252/fr.evbundle +5 -0
  29. pymetrix_eviews-0.1.0a1/tests/fixtures/cp1252/pages/m.csv +3 -0
  30. pymetrix_eviews-0.1.0a1/tests/fixtures/macro/export.log +2 -0
  31. pymetrix_eviews-0.1.0a1/tests/fixtures/macro/macro.evbundle +81 -0
  32. pymetrix_eviews-0.1.0a1/tests/fixtures/macro/objects/quarterly/eq_cons_est.csv +3 -0
  33. pymetrix_eviews-0.1.0a1/tests/fixtures/macro/objects/quarterly/eq_rev_est.csv +3 -0
  34. pymetrix_eviews-0.1.0a1/tests/fixtures/macro/objects/quarterly/eq_white_est.csv +3 -0
  35. pymetrix_eviews-0.1.0a1/tests/fixtures/macro/objects/quarterly/m2.csv +2 -0
  36. pymetrix_eviews-0.1.0a1/tests/fixtures/macro/objects/quarterly/w.csv +3 -0
  37. pymetrix_eviews-0.1.0a1/tests/fixtures/macro/pages/annual.csv +5 -0
  38. pymetrix_eviews-0.1.0a1/tests/fixtures/macro/pages/cross.csv +5 -0
  39. pymetrix_eviews-0.1.0a1/tests/fixtures/macro/pages/panel.csv +6 -0
  40. pymetrix_eviews-0.1.0a1/tests/fixtures/macro/pages/quarterly.csv +13 -0
  41. pymetrix_eviews-0.1.0a1/tests/fixtures/macro/text/quarterly/m.txt +3 -0
  42. pymetrix_eviews-0.1.0a1/tests/fixtures/macro/valmaps/quarterly/vm_sector.csv +4 -0
  43. pymetrix_eviews-0.1.0a1/tests/fixtures/missing_column/missing.evbundle +4 -0
  44. pymetrix_eviews-0.1.0a1/tests/fixtures/missing_column/pages/q.csv +3 -0
  45. pymetrix_eviews-0.1.0a1/tests/fixtures/newer/newer.evbundle +4 -0
  46. pymetrix_eviews-0.1.0a1/tests/fixtures/newer/pages/q.csv +3 -0
  47. pymetrix_eviews-0.1.0a1/tests/fixtures/no_manifest/export.log +1 -0
  48. pymetrix_eviews-0.1.0a1/tests/fixtures/no_manifest/pages/q.csv +2 -0
  49. pymetrix_eviews-0.1.0a1/tests/fixtures/programs/annual.prg +17 -0
  50. pymetrix_eviews-0.1.0a1/tests/fixtures/programs/hand.prg +43 -0
  51. pymetrix_eviews-0.1.0a1/tests/fixtures/semiannual/pages/s.csv +4 -0
  52. pymetrix_eviews-0.1.0a1/tests/fixtures/semiannual/semi.evbundle +4 -0
  53. pymetrix_eviews-0.1.0a1/tests/fixtures/weekly/pages/d5.csv +4 -0
  54. pymetrix_eviews-0.1.0a1/tests/fixtures/weekly/pages/d7.csv +3 -0
  55. pymetrix_eviews-0.1.0a1/tests/fixtures/weekly/pages/w.csv +4 -0
  56. pymetrix_eviews-0.1.0a1/tests/fixtures/weekly/weekly.evbundle +15 -0
  57. pymetrix_eviews-0.1.0a1/tests/test_bundle.py +495 -0
  58. pymetrix_eviews-0.1.0a1/tests/test_dialog.py +165 -0
  59. pymetrix_eviews-0.1.0a1/tests/test_program.py +381 -0
  60. pymetrix_eviews-0.1.0a1/tests/test_program_control.py +346 -0
  61. pymetrix_eviews-0.1.0a1/tests/test_program_estimation.py +468 -0
  62. pymetrix_eviews-0.1.0a1/tests/test_program_validation.py +157 -0
  63. pymetrix_eviews-0.1.0a1/tests/test_translation_panel.py +169 -0
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .pytest_cache/
5
+ .pytest_tmp/
6
+ .venv/
7
+ build/
8
+ dist/
9
+ .ipynb_checkpoints/
10
+ hs_err_pid*.log
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Geoffrey Heenan
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,248 @@
1
+ Metadata-Version: 2.5
2
+ Name: pymetrix-eviews
3
+ Version: 0.1.0a1
4
+ Summary: EViews workfiles into pymetrix: a bundle written by an (experimental) export program, read with its metadata, equations and models
5
+ Project-URL: Homepage, https://github.com/GeoffHeenan/pymetrix
6
+ Project-URL: Source, https://github.com/GeoffHeenan/pymetrix/tree/main/packages/pymetrix-eviews
7
+ Project-URL: Issues, https://github.com/GeoffHeenan/pymetrix/issues
8
+ Project-URL: Changelog, https://github.com/GeoffHeenan/pymetrix/blob/main/CHANGELOG.md
9
+ Author: Geoffrey Heenan
10
+ License-Expression: BSD-3-Clause
11
+ License-File: LICENSE
12
+ Requires-Python: >=3.11
13
+ Requires-Dist: pymetrix>=0.1.0a21
14
+ Provides-Extra: test
15
+ Requires-Dist: jsonschema>=4.18; extra == 'test'
16
+ Requires-Dist: pytest>=9.0.3; extra == 'test'
17
+ Description-Content-Type: text/markdown
18
+
19
+ # pymetrix-eviews
20
+
21
+ EViews work into pymetrix. This first version reads EViews **workfiles** through a *bundle*: a folder that an
22
+ export program, run once in your own EViews, writes from the open workfile. Each page becomes a pymetrix `Dataset`,
23
+ with its series' labels, units and sources, and the page's groups, samples, scalars, strings, matrices, value maps,
24
+ equations (with EViews's own estimates) and models. The binary `.wf1` file is not read: its format is not
25
+ published, and a misread column of numbers looks like data.
26
+
27
+ It also translates EViews **programs** (`.prg`): data work, estimation, tests and models so far (phases 1 and 2;
28
+ see "Programs" below). Running
29
+ EViews for you through COM is later work (see pymetrix's `docs/design/eviews-plugin.md`).
30
+
31
+ ## The export program is experimental
32
+
33
+ `pymetrix_export.prg` was written from EViews's public documentation and has **never been run in EViews**: the
34
+ project has no EViews licence. Every line whose syntax or behaviour must be checked is marked `(verify)` in it. It is
35
+ tested only through the reader, against bundles written by hand to the format and against the manifest's JSON
36
+ Schema.
37
+
38
+ **The supported way in, until the program has been checked**, is to save the workfile from EViews as CSV or Excel
39
+ (File → Save As, or `wfsave(type=...)`) and load that with pymetrix's **File → Load data…**. The label comes off once
40
+ someone with a licence has run the program on the two most recent major versions of EViews and its bundles match
41
+ the hand-made fixtures. If you have EViews, running it and reporting what happens is the most useful help there is.
42
+
43
+ ## Use
44
+
45
+ 1. In pymetrix: **File → Import EViews workfile…**, *Get the export program (experimental)*, and save `pymetrix_export.prg`
46
+ (or `save_export_program("C:/work")` in code).
47
+ 2. In EViews: open the workfile, then `exec pymetrix_export.prg C:\work\macro-export`.
48
+ 3. In pymetrix: **File → Import EViews workfile…**, *Workfile bundle*, and choose `C:\work\macro-export\macro.evbundle`.
49
+ Leave *Pages* empty for every page.
50
+
51
+ Each page is one line of the script, and of the History:
52
+
53
+ ```python
54
+ quarterly = Dataset.read("C:/work/macro-export/macro.evbundle", page="quarterly")
55
+ annual = Dataset.read("C:/work/macro-export/macro.evbundle", page="annual")
56
+ ```
57
+
58
+ Replaying them needs this plugin, as a PSETS project needs `pymetrix-psets`. Tick **Save the data as Parquet** to
59
+ write each page next to the bundle as `<page>.parquet` and read it from there: the script then needs only pymetrix
60
+ (a project still names the plugin's step, so reopening the project needs the plugin; load the Parquet files with
61
+ File → Load data to drop it).
62
+
63
+ In code:
64
+
65
+ ```python
66
+ from pymetrix_eviews import bundle_pages, compare_estimates, eviews_objects
67
+
68
+ bundle_pages("C:/work/macro-export/macro.evbundle") # each page: structure, frequency, how many series
69
+ objects = eviews_objects(quarterly) # groups as selections, samples, scalars, strings, matrices, models
70
+ compare_estimates(quarterly) # each least-squares equation refitted, beside EViews's estimates
71
+ ```
72
+
73
+ ## What is read, and where it goes
74
+
75
+ | EViews | pymetrix |
76
+ | --- | --- |
77
+ | a page | a `Dataset`, named after the page (made a valid Python name) |
78
+ | dated pages: A, Q, M, W, D5, D7 | a time axis of `Y`, `Q`, `M`, `W-<day>` (the week's last day, from the dates), `B`, `D` |
79
+ | semi-annual, multi-year, intraday, bimonthly, fortnightly, ten-day | refused with the reason; `undated=True` reads the page undated, its dates kept as the text series `date` |
80
+ | panel pages | a panel dataset (balanced or not), with the cross-section id as its entity axis |
81
+ | undated pages | a cross-section with an `obs` axis |
82
+ | NA, an empty numeric field | missing |
83
+ | alpha series | text (pandas `string`); an empty value is missing |
84
+ | value maps | the codes stay as data; the map goes in `Variable.extra["value_map"]` (pymetrix has no value labels) |
85
+ | display name, description, units, source | `Variable.label` (the display name, else the description), `description`, `units`, `source` |
86
+ | remarks, attributes | `Variable.extra` |
87
+ | groups, samples | `meta.extra["eviews"]`; `eviews_objects` gives a `Selection` and a `Sample` |
88
+ | scalars, strings | `meta.extra["eviews"]`; a model's scalars are its parameters in `bundle_model` |
89
+ | vectors, matrices, sym, coef | `meta.extra["eviews"]`; `eviews_objects` gives `Matrix` objects |
90
+ | equations | the command, method, sample and EViews's estimates, in `meta.extra["eviews"]`; `compare_estimates` refits the least-squares ones |
91
+ | models | the text, in `meta.extra["eviews"]`; `bundle_model(data, name)` reads it with `read_eviews` |
92
+ | other objects (graphs, tables, spools...) | listed in `meta.extra["eviews"]["skipped"]` |
93
+
94
+ What does not read is refused at its place, never misread: a folder without its manifest (an incomplete export:
95
+ the program writes the manifest last), a bundle of a newer `format_version` ("update pymetrix-eviews"), a CSV
96
+ without a column the manifest lists, a value that is not a number, a date that does not start a period of the
97
+ page's frequency, a file outside the bundle's folder. Each error names the file, line and column, or the manifest's
98
+ key. Keys the reader does not know are kept in `meta.extra["eviews"]["unknown"]` with a note, as the format's
99
+ version 1 grows only by adding. Files are read as UTF-8; one that is not falls back to Windows-1252 with a note.
100
+
101
+ ## The bundle, format version 1
102
+
103
+ ```
104
+ macro-export/
105
+ macro.evbundle the manifest (JSON, UTF-8): the file pymetrix opens
106
+ pages/<page>.csv a page's series: the date (pmx_date) and id columns, then every series and alpha series
107
+ text/<page>/<object>.txt long texts: a model's text, a command over several lines
108
+ objects/<page>/<name>.csv vectors, matrices, sym, coef (one line per row, no header); <equation>_est.csv
109
+ (coefficient,estimate,std_error)
110
+ valmaps/<page>/<name>.csv value maps: value,label
111
+ export.log the program's record of what it exported and skipped
112
+ ```
113
+
114
+ The manifest's JSON Schema is `src/pymetrix_eviews/bundle-1.schema.json` (`bundle_schema()`); pymetrix's
115
+ `docs/design/eviews-plugin.md` describes each key.
116
+
117
+ ## Programs
118
+
119
+ `translate_program` turns an EViews program into a readable pymetrix script, a report with a row for every line,
120
+ and the same work as recorded steps:
121
+
122
+ ```python
123
+ from pymetrix_eviews import translate_program
124
+
125
+ t = translate_program("C:/work/macro.prg", bundle="C:/work/macro-export/macro.evbundle")
126
+ print(t.script) # each EViews line as a comment, above what it became
127
+ t.report.summary() # line, status (translated, translated with a note, left out, error), EViews, Python, reason
128
+ out = t.run(session) # steps mode: each data statement a recorded step; scalars, strings, matrices returned
129
+ ```
130
+
131
+ `bundle` is what the program's `wfopen` opens: the bundle, or a CSV or Excel file saved from the workfile in EViews
132
+ (with `read_options={"time": "obs", "freq": "Q"}`, `Dataset.read`'s options). A program that starts with `wfcreate`
133
+ needs neither. `run` keeps the script and the report in the project (`session.attachments["pymetrix-eviews"]`).
134
+
135
+ Phase 1, data work:
136
+
137
+ | EViews | pymetrix |
138
+ | --- | --- |
139
+ | `wfopen`, `wfcreate`, `pagecreate`, `pageselect` | `Dataset.read(...)`, `Dataset.empty("Q", "1990Q1", "2030Q4")`, a variable per page |
140
+ | `smpl 1990q1 @last`, `smpl @first+4 2000q4 if x > 0`, `sample s ...`, `smpl s` | `data.with_sample(Sample(...))`, a `Sample` variable |
141
+ | `series y = ...`, `genr`, `y = ...` | `data.with_series(y="...", within=Sample(...))` under a sample; period by period when the formula uses `y` |
142
+ | `series y`, `y = na` | `data.with_series(y=None)` |
143
+ | `frml y = ...` | `data.derive(y="...")` |
144
+ | `group g a b`, `g.add c` | `g = data.series("a", "b")` |
145
+ | `x.label(d)`, `x.label(u)`, `x.label(s)`, `x.displayname`, `x.setattr(units)` | `data.with_info("x", ...)` |
146
+ | `rename a b`, `delete a b`, `x.fill(o=2000q1) 1, 2` | `data.rename(a="b")`, `data.drop("a", "b")`, `data.edit({...})` |
147
+ | `scalar s = 0.3`, `!i = 2`, `%s = "a"`, `string s = "a"` | Python variables; `{%s}` and `{!i}` put in where known before the program runs |
148
+ | `scalar m = @mean(x)` (also `@sum`, `@min`, `@max`, `@stdev`, `@median`, `@obs`) | `float(data.eval("x")[data.sample_mask()].mean())` |
149
+ | `vector(3) v`, `matrix(2,2) m`, `m.fill 1, 2, 3, 4` | `Matrix.zeros(3, 1)`, `Matrix([[1, 3], [2, 4]])` (by column, as EViews) |
150
+
151
+ Phase 2, estimation, tests and models:
152
+
153
+ | EViews | pymetrix |
154
+ | --- | --- |
155
+ | `equation eq.ls(cov=white) y c x y(-1)`, `eq.ls ...`, `ls ...` | `eq = Equation("y ~ x + y[-1]", name="eq").fit(data, method=OLS(cov="white"))` |
156
+ | `ls y = c(1) + c(2)*x` | `Equation("y ~ c_1 + c_2*x", params=("c_1", "c_2")).fit(data)` |
157
+ | `ls y c x ar(1)` | `Equation("y ~ x", errors=ARMA(ar=1)).fit(data, method=ML())`, with a note on EViews's ARMA estimator |
158
+ | `tsls`, `gmm`, `liml` with `@` instruments | `IV(endog=..., instruments=...)`, `GMM(instruments=...)`, `LIML(...)` |
159
+ | `arch(1,1)`, `binary(d=l)`, `ordered`, `censored(l=0)`, `count`, `qreg(quant=.25)`, `heckit ... @ s c z`, `ardl` | `GARCH`, `Logit`/`Probit`, `OrderedProbit`, `Tobit`, `Poisson`, `Quantile`, `Heckman`, `ARDL` |
160
+ | `var v.ls 1 4 y1 y2 @ c x`, `v.ec(c, 1) 1 4 y1 y2` | `VAR(("y1", "y2"), lags=4, exog=("x",))`, `VECM(...)` |
161
+ | `system s`, `s.append ...`, `s.sur` (`3sls`, `fiml`, `tsls`) | `System([...]).fit(data, method=SUR())` |
162
+ | `eq.wald c(2)=0`, `eq.testdrop x`, `eq.auto(4)`, `eq.hettest`, `eq.archtest(1)`, `eq.reset(1)`, `eq.chow 2000q1`, `eq.hist`, `eq.rls(q)` | `eq.test("wald", "x=0")`, `"breusch_godfrey"`, `"breusch_pagan"`, `"arch"`, `"reset"`, `"chow"`, `"jarque_bera"`, `eq.recursive_residuals()` |
163
+ | `x.uroot(adf, const)`, `g.coint(c, 4)` | `data.test("adf", "x", trend="c", lags="bic")`, `data.johansen((...), lags=4)` |
164
+ | `scalar b = eq.@coefs(2)`, `@stderrs`, `@r2`, `@aic`, `c(2)` | `float(eq.params["x"])`, ...; `@aic` per observation, as EViews |
165
+ | `eq.forecast yf`, `eq.fit yf`, `eq.makeresids r` | `eq.forecast(data, span, dynamic=True)`, then `data.with_series(yf=...)`; `data.with_series(r=eq.resid)` |
166
+ | `model m`, `m.append`, `m.merge eq`, `@identity`, `@add`, `@innov` | collected, then `m = read_eviews(text, data=..., params=...)`; its refusals at their lines |
167
+ | `m.solveopt(o=g)`, `m.addassign @all`, `m.addinit(v=n) @all`, `m.scenario(n, a=_1) "s"`, `m.override x`, `m.exclude y`, `m.solve` | `GaussSeidel()`, `m_model.add_factors(data, span)`, `Scenario(adjust=..., fix=...)`, `m_model.solve(...)`, the series added to the page as `y_0`, `y_1` |
168
+
169
+ An option that is not mapped leaves the line out, naming it; where EViews's defaults differ from pymetrix's, the line
170
+ is translated with a note saying what to check.
171
+
172
+ Phase 3, control flow (loops stay loops in the script; steps mode runs them in Python and records flat steps):
173
+
174
+ | EViews | pymetrix |
175
+ | --- | --- |
176
+ | `for !i = 1 to n step k ... next` | `for i in range(1, n + 1, k):` |
177
+ | `for %s a b c ... next`, `for %s {%names}` | `for s in ["a", "b", "c"]:`, `for s in names.split():` |
178
+ | `while !x < 100 ... wend` | `while x < 100:`; steps mode stops after `while_cap` passes (10,000) |
179
+ | `if %s = "a" and eq.@r2 > 0.5 then ... else ... endif` | `if s == "a" and eq.stats["r2"] > 0.5:`, decided as the program runs |
180
+ | `exitloop`, `return`, `stop` | `break`, `return`, `raise SystemExit` |
181
+ | `subroutine f(string %a, scalar !b) ... endsub`, `call f(%x, 2)` | `def f(a, b): ...` at the top of the script; `x = f(x, 2)` when `f` assigns `%a` (arguments by reference) |
182
+ | `subroutine local f(...)` | a function that shares none of the program's names |
183
+ | `include lib` | `lib.prg` translated in line, its rows under its name |
184
+ | `series y_{%s} = log(x_{%s})`, `equation eq_{%c}.ls ...` | `with_series(**{f"y_{s}": f"log(x_{s})"})`, `globals()[f"eq_{c}"] = ...` |
185
+ | `%0`, `%1` | `arg0`, `arg1`: the script's parameters (`translate_program(..., args="us 2020q1")`) |
186
+ | `@word`, `@wcount`, `@wfind`, `@wlookup`, `@isobject`, `@lower`, `@replace`, `@mid`..., `g.@count`, `g.@seriesname(i)`, `@sum(x)`, `@obssmpl` | `s.split()[i - 1]`, `len(s.split())`, `" ".join(q.series("x*").names)`, `"x" in q.names`, `len(g.names)`... |
187
+ | `m.makegroup(a,n) g @endog` | `g = q.series(*m_model.endogenous)` |
188
+
189
+ What a program uses but does not make (in EViews an add-in or a database makes it) is given with `objects=`: the
190
+ FRB/US programs' model, read by `read_eviews_xml`, as `objects={"stdver": model}`; the script expects it under that
191
+ name and steps mode puts it in the session.
192
+
193
+ In the app, **File → Translate EViews program…** asks for the program, its workfile data and its arguments, and the
194
+ **EViews translation** panel (View → EViews translation, docked at the bottom) shows the report: a row per line with
195
+ its status in words and colour, the program and the script side by side following the selected row, a filter per
196
+ status with its count, Copy, Copy script, and Run as steps (each step recorded and undoable; the run stops at the
197
+ first step that fails and marks its row).
198
+
199
+ Left out, each with its reason and pymetrix's way where there is one: `stepls`, `breakls`, `threshold`, `switchreg`,
200
+ `glm` and `nls`, `testadd` and the extreme-value link (gaps), graphs, tables, spools and display, databases, add-ins,
201
+ object parameters of subroutines, names with `$`, and expression functions pymetrix has no equivalent of (`@date`,
202
+ `@trend`, `@seas` and `@elem` in data work, `@obssmpl` inside a series' formula, `@strdate`, by-group statistics
203
+ grouped by an expression; pymetrix's known gaps lists them).
204
+
205
+ Expression functions and random numbers:
206
+
207
+ | EViews | pymetrix |
208
+ | --- | --- |
209
+ | `@log10`, `@floor`, `@ceiling`, `@round(x)`, `@isna`, `@nan(x, v)`, `na` | `log10`, `floor`, `ceil`, `round(x)` (halves away from zero), `isna`, `fillna(x, v)`, `na` |
210
+ | `@iif(c, a, b)`, `@recode(c, a, b)` | `iif(c, a, b)` (missing where `c` is); `@recode(a > b, a, b)` stays `max(a, b)` |
211
+ | `@year`, `@quarter`, `@month`, `@day` | `year()`, `quarter()`, `month()`, `day()`: of each period's first day |
212
+ | `@obsnum`, `@obsid` | `obsnum()`, from 1 within each cross-section (EViews's `@obsnum` counts a panel's rows straight through) |
213
+ | `@cumsum(x)` | `cumsum(x)`: NAs skipped, as EViews's; over all the page's rows (EViews: the current sample; a line under a `smpl` says so) |
214
+ | `@sumsby(x, g)`, `@meansby`, `@minsby`, `@maxsby` | `sum(x, by=g)`, `mean`, `min`, `max`, with `g` a series' name; over all the page's rows |
215
+ | `rndseed n`, then `nrnd`, `@rnorm`, `rnd`, `@runif(a, b)` | `normrnd(seed=s)`, `unifrnd(seed=s)`, `unifrnd(a, b, seed=s)`, `s` = n·1000 + the draw's number after the `rndseed` (1, 2, ... without one); pymetrix's generator, so the numbers are never EViews's: each line is translated with a note "to check" |
216
+
217
+ None of these is read in a model's equations (`read_eviews` refuses them, saying why): a model has no rows.
218
+
219
+ EViews's dates (`@dateval`, `@datestr` with a format, `@dateadd`, `@datediff`, `@dtoo`, `@otod`) act on a program's
220
+ `%` strings and `!` numbers, so they are worked out as Python values by `pymetrix_eviews.dates`, with EViews's date
221
+ numbers (days since 1 January A.D. 1, that day 0): at translation time when the program's values are known, otherwise
222
+ when the script runs (it then imports `pymetrix_eviews.dates as eviews_dates`). FRB/US's `dateshift` subroutine
223
+ translates as the package writes it.
224
+
225
+ ## Installing
226
+
227
+ ```bash
228
+ pip install -e packages/pymetrix-eviews # from the pymetrix repository
229
+ ```
230
+
231
+ It needs nothing beyond pymetrix. Its tests (`pip install -e "packages/pymetrix-eviews[test]"`) check the hand-made
232
+ fixtures against the schema with `jsonschema`.
233
+
234
+ ## Tests
235
+
236
+ `tests/fixtures/` holds bundles written by hand, independently of the reader: a workfile of four pages (quarterly,
237
+ annual, a panel, an undated cross-section) with every case above, and malformed bundles that must be refused. The
238
+ "EViews estimates" in them were computed with NumPy's least squares on the fixture's data, and a test recomputes
239
+ them. The tests check every value and metadata field read, the refusals and their places, the dialog against the
240
+ `Dataset.read` calls it stands for, and that the scripts replay.
241
+
242
+ `tests/fixtures/programs/` holds EViews programs written for the tests; `test_program.py` checks every value they
243
+ make against values worked out by hand, and that the script and the steps give equal objects.
244
+ `test_program_control.py` does the same for loops, `if` blocks, subroutines, included programs and the program's
245
+ arguments. `test_program_validation.py` translates Brillet's and the FRB/US programs (`PYMETRIX_BRILLET`,
246
+ `PYMETRIX_FRBUS`; skipped without them) and fixes the count of each status; with the FRB/US data package too
247
+ (`PYMETRIX_FRBUS_DATA`), it runs example1.prg, given the model and LONGBASE, against the same simulation written by
248
+ hand.
@@ -0,0 +1,230 @@
1
+ # pymetrix-eviews
2
+
3
+ EViews work into pymetrix. This first version reads EViews **workfiles** through a *bundle*: a folder that an
4
+ export program, run once in your own EViews, writes from the open workfile. Each page becomes a pymetrix `Dataset`,
5
+ with its series' labels, units and sources, and the page's groups, samples, scalars, strings, matrices, value maps,
6
+ equations (with EViews's own estimates) and models. The binary `.wf1` file is not read: its format is not
7
+ published, and a misread column of numbers looks like data.
8
+
9
+ It also translates EViews **programs** (`.prg`): data work, estimation, tests and models so far (phases 1 and 2;
10
+ see "Programs" below). Running
11
+ EViews for you through COM is later work (see pymetrix's `docs/design/eviews-plugin.md`).
12
+
13
+ ## The export program is experimental
14
+
15
+ `pymetrix_export.prg` was written from EViews's public documentation and has **never been run in EViews**: the
16
+ project has no EViews licence. Every line whose syntax or behaviour must be checked is marked `(verify)` in it. It is
17
+ tested only through the reader, against bundles written by hand to the format and against the manifest's JSON
18
+ Schema.
19
+
20
+ **The supported way in, until the program has been checked**, is to save the workfile from EViews as CSV or Excel
21
+ (File → Save As, or `wfsave(type=...)`) and load that with pymetrix's **File → Load data…**. The label comes off once
22
+ someone with a licence has run the program on the two most recent major versions of EViews and its bundles match
23
+ the hand-made fixtures. If you have EViews, running it and reporting what happens is the most useful help there is.
24
+
25
+ ## Use
26
+
27
+ 1. In pymetrix: **File → Import EViews workfile…**, *Get the export program (experimental)*, and save `pymetrix_export.prg`
28
+ (or `save_export_program("C:/work")` in code).
29
+ 2. In EViews: open the workfile, then `exec pymetrix_export.prg C:\work\macro-export`.
30
+ 3. In pymetrix: **File → Import EViews workfile…**, *Workfile bundle*, and choose `C:\work\macro-export\macro.evbundle`.
31
+ Leave *Pages* empty for every page.
32
+
33
+ Each page is one line of the script, and of the History:
34
+
35
+ ```python
36
+ quarterly = Dataset.read("C:/work/macro-export/macro.evbundle", page="quarterly")
37
+ annual = Dataset.read("C:/work/macro-export/macro.evbundle", page="annual")
38
+ ```
39
+
40
+ Replaying them needs this plugin, as a PSETS project needs `pymetrix-psets`. Tick **Save the data as Parquet** to
41
+ write each page next to the bundle as `<page>.parquet` and read it from there: the script then needs only pymetrix
42
+ (a project still names the plugin's step, so reopening the project needs the plugin; load the Parquet files with
43
+ File → Load data to drop it).
44
+
45
+ In code:
46
+
47
+ ```python
48
+ from pymetrix_eviews import bundle_pages, compare_estimates, eviews_objects
49
+
50
+ bundle_pages("C:/work/macro-export/macro.evbundle") # each page: structure, frequency, how many series
51
+ objects = eviews_objects(quarterly) # groups as selections, samples, scalars, strings, matrices, models
52
+ compare_estimates(quarterly) # each least-squares equation refitted, beside EViews's estimates
53
+ ```
54
+
55
+ ## What is read, and where it goes
56
+
57
+ | EViews | pymetrix |
58
+ | --- | --- |
59
+ | a page | a `Dataset`, named after the page (made a valid Python name) |
60
+ | dated pages: A, Q, M, W, D5, D7 | a time axis of `Y`, `Q`, `M`, `W-<day>` (the week's last day, from the dates), `B`, `D` |
61
+ | semi-annual, multi-year, intraday, bimonthly, fortnightly, ten-day | refused with the reason; `undated=True` reads the page undated, its dates kept as the text series `date` |
62
+ | panel pages | a panel dataset (balanced or not), with the cross-section id as its entity axis |
63
+ | undated pages | a cross-section with an `obs` axis |
64
+ | NA, an empty numeric field | missing |
65
+ | alpha series | text (pandas `string`); an empty value is missing |
66
+ | value maps | the codes stay as data; the map goes in `Variable.extra["value_map"]` (pymetrix has no value labels) |
67
+ | display name, description, units, source | `Variable.label` (the display name, else the description), `description`, `units`, `source` |
68
+ | remarks, attributes | `Variable.extra` |
69
+ | groups, samples | `meta.extra["eviews"]`; `eviews_objects` gives a `Selection` and a `Sample` |
70
+ | scalars, strings | `meta.extra["eviews"]`; a model's scalars are its parameters in `bundle_model` |
71
+ | vectors, matrices, sym, coef | `meta.extra["eviews"]`; `eviews_objects` gives `Matrix` objects |
72
+ | equations | the command, method, sample and EViews's estimates, in `meta.extra["eviews"]`; `compare_estimates` refits the least-squares ones |
73
+ | models | the text, in `meta.extra["eviews"]`; `bundle_model(data, name)` reads it with `read_eviews` |
74
+ | other objects (graphs, tables, spools...) | listed in `meta.extra["eviews"]["skipped"]` |
75
+
76
+ What does not read is refused at its place, never misread: a folder without its manifest (an incomplete export:
77
+ the program writes the manifest last), a bundle of a newer `format_version` ("update pymetrix-eviews"), a CSV
78
+ without a column the manifest lists, a value that is not a number, a date that does not start a period of the
79
+ page's frequency, a file outside the bundle's folder. Each error names the file, line and column, or the manifest's
80
+ key. Keys the reader does not know are kept in `meta.extra["eviews"]["unknown"]` with a note, as the format's
81
+ version 1 grows only by adding. Files are read as UTF-8; one that is not falls back to Windows-1252 with a note.
82
+
83
+ ## The bundle, format version 1
84
+
85
+ ```
86
+ macro-export/
87
+ macro.evbundle the manifest (JSON, UTF-8): the file pymetrix opens
88
+ pages/<page>.csv a page's series: the date (pmx_date) and id columns, then every series and alpha series
89
+ text/<page>/<object>.txt long texts: a model's text, a command over several lines
90
+ objects/<page>/<name>.csv vectors, matrices, sym, coef (one line per row, no header); <equation>_est.csv
91
+ (coefficient,estimate,std_error)
92
+ valmaps/<page>/<name>.csv value maps: value,label
93
+ export.log the program's record of what it exported and skipped
94
+ ```
95
+
96
+ The manifest's JSON Schema is `src/pymetrix_eviews/bundle-1.schema.json` (`bundle_schema()`); pymetrix's
97
+ `docs/design/eviews-plugin.md` describes each key.
98
+
99
+ ## Programs
100
+
101
+ `translate_program` turns an EViews program into a readable pymetrix script, a report with a row for every line,
102
+ and the same work as recorded steps:
103
+
104
+ ```python
105
+ from pymetrix_eviews import translate_program
106
+
107
+ t = translate_program("C:/work/macro.prg", bundle="C:/work/macro-export/macro.evbundle")
108
+ print(t.script) # each EViews line as a comment, above what it became
109
+ t.report.summary() # line, status (translated, translated with a note, left out, error), EViews, Python, reason
110
+ out = t.run(session) # steps mode: each data statement a recorded step; scalars, strings, matrices returned
111
+ ```
112
+
113
+ `bundle` is what the program's `wfopen` opens: the bundle, or a CSV or Excel file saved from the workfile in EViews
114
+ (with `read_options={"time": "obs", "freq": "Q"}`, `Dataset.read`'s options). A program that starts with `wfcreate`
115
+ needs neither. `run` keeps the script and the report in the project (`session.attachments["pymetrix-eviews"]`).
116
+
117
+ Phase 1, data work:
118
+
119
+ | EViews | pymetrix |
120
+ | --- | --- |
121
+ | `wfopen`, `wfcreate`, `pagecreate`, `pageselect` | `Dataset.read(...)`, `Dataset.empty("Q", "1990Q1", "2030Q4")`, a variable per page |
122
+ | `smpl 1990q1 @last`, `smpl @first+4 2000q4 if x > 0`, `sample s ...`, `smpl s` | `data.with_sample(Sample(...))`, a `Sample` variable |
123
+ | `series y = ...`, `genr`, `y = ...` | `data.with_series(y="...", within=Sample(...))` under a sample; period by period when the formula uses `y` |
124
+ | `series y`, `y = na` | `data.with_series(y=None)` |
125
+ | `frml y = ...` | `data.derive(y="...")` |
126
+ | `group g a b`, `g.add c` | `g = data.series("a", "b")` |
127
+ | `x.label(d)`, `x.label(u)`, `x.label(s)`, `x.displayname`, `x.setattr(units)` | `data.with_info("x", ...)` |
128
+ | `rename a b`, `delete a b`, `x.fill(o=2000q1) 1, 2` | `data.rename(a="b")`, `data.drop("a", "b")`, `data.edit({...})` |
129
+ | `scalar s = 0.3`, `!i = 2`, `%s = "a"`, `string s = "a"` | Python variables; `{%s}` and `{!i}` put in where known before the program runs |
130
+ | `scalar m = @mean(x)` (also `@sum`, `@min`, `@max`, `@stdev`, `@median`, `@obs`) | `float(data.eval("x")[data.sample_mask()].mean())` |
131
+ | `vector(3) v`, `matrix(2,2) m`, `m.fill 1, 2, 3, 4` | `Matrix.zeros(3, 1)`, `Matrix([[1, 3], [2, 4]])` (by column, as EViews) |
132
+
133
+ Phase 2, estimation, tests and models:
134
+
135
+ | EViews | pymetrix |
136
+ | --- | --- |
137
+ | `equation eq.ls(cov=white) y c x y(-1)`, `eq.ls ...`, `ls ...` | `eq = Equation("y ~ x + y[-1]", name="eq").fit(data, method=OLS(cov="white"))` |
138
+ | `ls y = c(1) + c(2)*x` | `Equation("y ~ c_1 + c_2*x", params=("c_1", "c_2")).fit(data)` |
139
+ | `ls y c x ar(1)` | `Equation("y ~ x", errors=ARMA(ar=1)).fit(data, method=ML())`, with a note on EViews's ARMA estimator |
140
+ | `tsls`, `gmm`, `liml` with `@` instruments | `IV(endog=..., instruments=...)`, `GMM(instruments=...)`, `LIML(...)` |
141
+ | `arch(1,1)`, `binary(d=l)`, `ordered`, `censored(l=0)`, `count`, `qreg(quant=.25)`, `heckit ... @ s c z`, `ardl` | `GARCH`, `Logit`/`Probit`, `OrderedProbit`, `Tobit`, `Poisson`, `Quantile`, `Heckman`, `ARDL` |
142
+ | `var v.ls 1 4 y1 y2 @ c x`, `v.ec(c, 1) 1 4 y1 y2` | `VAR(("y1", "y2"), lags=4, exog=("x",))`, `VECM(...)` |
143
+ | `system s`, `s.append ...`, `s.sur` (`3sls`, `fiml`, `tsls`) | `System([...]).fit(data, method=SUR())` |
144
+ | `eq.wald c(2)=0`, `eq.testdrop x`, `eq.auto(4)`, `eq.hettest`, `eq.archtest(1)`, `eq.reset(1)`, `eq.chow 2000q1`, `eq.hist`, `eq.rls(q)` | `eq.test("wald", "x=0")`, `"breusch_godfrey"`, `"breusch_pagan"`, `"arch"`, `"reset"`, `"chow"`, `"jarque_bera"`, `eq.recursive_residuals()` |
145
+ | `x.uroot(adf, const)`, `g.coint(c, 4)` | `data.test("adf", "x", trend="c", lags="bic")`, `data.johansen((...), lags=4)` |
146
+ | `scalar b = eq.@coefs(2)`, `@stderrs`, `@r2`, `@aic`, `c(2)` | `float(eq.params["x"])`, ...; `@aic` per observation, as EViews |
147
+ | `eq.forecast yf`, `eq.fit yf`, `eq.makeresids r` | `eq.forecast(data, span, dynamic=True)`, then `data.with_series(yf=...)`; `data.with_series(r=eq.resid)` |
148
+ | `model m`, `m.append`, `m.merge eq`, `@identity`, `@add`, `@innov` | collected, then `m = read_eviews(text, data=..., params=...)`; its refusals at their lines |
149
+ | `m.solveopt(o=g)`, `m.addassign @all`, `m.addinit(v=n) @all`, `m.scenario(n, a=_1) "s"`, `m.override x`, `m.exclude y`, `m.solve` | `GaussSeidel()`, `m_model.add_factors(data, span)`, `Scenario(adjust=..., fix=...)`, `m_model.solve(...)`, the series added to the page as `y_0`, `y_1` |
150
+
151
+ An option that is not mapped leaves the line out, naming it; where EViews's defaults differ from pymetrix's, the line
152
+ is translated with a note saying what to check.
153
+
154
+ Phase 3, control flow (loops stay loops in the script; steps mode runs them in Python and records flat steps):
155
+
156
+ | EViews | pymetrix |
157
+ | --- | --- |
158
+ | `for !i = 1 to n step k ... next` | `for i in range(1, n + 1, k):` |
159
+ | `for %s a b c ... next`, `for %s {%names}` | `for s in ["a", "b", "c"]:`, `for s in names.split():` |
160
+ | `while !x < 100 ... wend` | `while x < 100:`; steps mode stops after `while_cap` passes (10,000) |
161
+ | `if %s = "a" and eq.@r2 > 0.5 then ... else ... endif` | `if s == "a" and eq.stats["r2"] > 0.5:`, decided as the program runs |
162
+ | `exitloop`, `return`, `stop` | `break`, `return`, `raise SystemExit` |
163
+ | `subroutine f(string %a, scalar !b) ... endsub`, `call f(%x, 2)` | `def f(a, b): ...` at the top of the script; `x = f(x, 2)` when `f` assigns `%a` (arguments by reference) |
164
+ | `subroutine local f(...)` | a function that shares none of the program's names |
165
+ | `include lib` | `lib.prg` translated in line, its rows under its name |
166
+ | `series y_{%s} = log(x_{%s})`, `equation eq_{%c}.ls ...` | `with_series(**{f"y_{s}": f"log(x_{s})"})`, `globals()[f"eq_{c}"] = ...` |
167
+ | `%0`, `%1` | `arg0`, `arg1`: the script's parameters (`translate_program(..., args="us 2020q1")`) |
168
+ | `@word`, `@wcount`, `@wfind`, `@wlookup`, `@isobject`, `@lower`, `@replace`, `@mid`..., `g.@count`, `g.@seriesname(i)`, `@sum(x)`, `@obssmpl` | `s.split()[i - 1]`, `len(s.split())`, `" ".join(q.series("x*").names)`, `"x" in q.names`, `len(g.names)`... |
169
+ | `m.makegroup(a,n) g @endog` | `g = q.series(*m_model.endogenous)` |
170
+
171
+ What a program uses but does not make (in EViews an add-in or a database makes it) is given with `objects=`: the
172
+ FRB/US programs' model, read by `read_eviews_xml`, as `objects={"stdver": model}`; the script expects it under that
173
+ name and steps mode puts it in the session.
174
+
175
+ In the app, **File → Translate EViews program…** asks for the program, its workfile data and its arguments, and the
176
+ **EViews translation** panel (View → EViews translation, docked at the bottom) shows the report: a row per line with
177
+ its status in words and colour, the program and the script side by side following the selected row, a filter per
178
+ status with its count, Copy, Copy script, and Run as steps (each step recorded and undoable; the run stops at the
179
+ first step that fails and marks its row).
180
+
181
+ Left out, each with its reason and pymetrix's way where there is one: `stepls`, `breakls`, `threshold`, `switchreg`,
182
+ `glm` and `nls`, `testadd` and the extreme-value link (gaps), graphs, tables, spools and display, databases, add-ins,
183
+ object parameters of subroutines, names with `$`, and expression functions pymetrix has no equivalent of (`@date`,
184
+ `@trend`, `@seas` and `@elem` in data work, `@obssmpl` inside a series' formula, `@strdate`, by-group statistics
185
+ grouped by an expression; pymetrix's known gaps lists them).
186
+
187
+ Expression functions and random numbers:
188
+
189
+ | EViews | pymetrix |
190
+ | --- | --- |
191
+ | `@log10`, `@floor`, `@ceiling`, `@round(x)`, `@isna`, `@nan(x, v)`, `na` | `log10`, `floor`, `ceil`, `round(x)` (halves away from zero), `isna`, `fillna(x, v)`, `na` |
192
+ | `@iif(c, a, b)`, `@recode(c, a, b)` | `iif(c, a, b)` (missing where `c` is); `@recode(a > b, a, b)` stays `max(a, b)` |
193
+ | `@year`, `@quarter`, `@month`, `@day` | `year()`, `quarter()`, `month()`, `day()`: of each period's first day |
194
+ | `@obsnum`, `@obsid` | `obsnum()`, from 1 within each cross-section (EViews's `@obsnum` counts a panel's rows straight through) |
195
+ | `@cumsum(x)` | `cumsum(x)`: NAs skipped, as EViews's; over all the page's rows (EViews: the current sample; a line under a `smpl` says so) |
196
+ | `@sumsby(x, g)`, `@meansby`, `@minsby`, `@maxsby` | `sum(x, by=g)`, `mean`, `min`, `max`, with `g` a series' name; over all the page's rows |
197
+ | `rndseed n`, then `nrnd`, `@rnorm`, `rnd`, `@runif(a, b)` | `normrnd(seed=s)`, `unifrnd(seed=s)`, `unifrnd(a, b, seed=s)`, `s` = n·1000 + the draw's number after the `rndseed` (1, 2, ... without one); pymetrix's generator, so the numbers are never EViews's: each line is translated with a note "to check" |
198
+
199
+ None of these is read in a model's equations (`read_eviews` refuses them, saying why): a model has no rows.
200
+
201
+ EViews's dates (`@dateval`, `@datestr` with a format, `@dateadd`, `@datediff`, `@dtoo`, `@otod`) act on a program's
202
+ `%` strings and `!` numbers, so they are worked out as Python values by `pymetrix_eviews.dates`, with EViews's date
203
+ numbers (days since 1 January A.D. 1, that day 0): at translation time when the program's values are known, otherwise
204
+ when the script runs (it then imports `pymetrix_eviews.dates as eviews_dates`). FRB/US's `dateshift` subroutine
205
+ translates as the package writes it.
206
+
207
+ ## Installing
208
+
209
+ ```bash
210
+ pip install -e packages/pymetrix-eviews # from the pymetrix repository
211
+ ```
212
+
213
+ It needs nothing beyond pymetrix. Its tests (`pip install -e "packages/pymetrix-eviews[test]"`) check the hand-made
214
+ fixtures against the schema with `jsonschema`.
215
+
216
+ ## Tests
217
+
218
+ `tests/fixtures/` holds bundles written by hand, independently of the reader: a workfile of four pages (quarterly,
219
+ annual, a panel, an undated cross-section) with every case above, and malformed bundles that must be refused. The
220
+ "EViews estimates" in them were computed with NumPy's least squares on the fixture's data, and a test recomputes
221
+ them. The tests check every value and metadata field read, the refusals and their places, the dialog against the
222
+ `Dataset.read` calls it stands for, and that the scripts replay.
223
+
224
+ `tests/fixtures/programs/` holds EViews programs written for the tests; `test_program.py` checks every value they
225
+ make against values worked out by hand, and that the script and the steps give equal objects.
226
+ `test_program_control.py` does the same for loops, `if` blocks, subroutines, included programs and the program's
227
+ arguments. `test_program_validation.py` translates Brillet's and the FRB/US programs (`PYMETRIX_BRILLET`,
228
+ `PYMETRIX_FRBUS`; skipped without them) and fixes the count of each status; with the FRB/US data package too
229
+ (`PYMETRIX_FRBUS_DATA`), it runs example1.prg, given the model and LONGBASE, against the same simulation written by
230
+ hand.
@@ -0,0 +1,37 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pymetrix-eviews"
7
+ dynamic = ["version"]
8
+ description = "EViews workfiles into pymetrix: a bundle written by an (experimental) export program, read with its metadata, equations and models"
9
+ readme = "README.md"
10
+ license = "BSD-3-Clause"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.11"
13
+ authors = [{ name = "Geoffrey Heenan" }]
14
+ dependencies = ["pymetrix>=0.1.0a21"] # extension API 1.10 (0.1.0a21)
15
+
16
+ [project.urls]
17
+ Homepage = "https://github.com/GeoffHeenan/pymetrix"
18
+ Source = "https://github.com/GeoffHeenan/pymetrix/tree/main/packages/pymetrix-eviews"
19
+ Issues = "https://github.com/GeoffHeenan/pymetrix/issues"
20
+ Changelog = "https://github.com/GeoffHeenan/pymetrix/blob/main/CHANGELOG.md"
21
+
22
+ [project.optional-dependencies]
23
+ test = ["pytest>=9.0.3", "jsonschema>=4.18"] # the fixtures are checked against the manifest's JSON Schema
24
+
25
+ # importing the package registers the .evbundle reader, the File > Import EViews workfile... dialog and its help topic
26
+ [project.entry-points."pymetrix.plugins"]
27
+ eviews = "pymetrix_eviews:register"
28
+ [project.entry-points."pymetrix.io"]
29
+ eviews = "pymetrix_eviews:register"
30
+ [project.entry-points."pymetrix.commands"]
31
+ eviews = "pymetrix_eviews:register"
32
+
33
+ [tool.hatch.version]
34
+ path = "src/pymetrix_eviews/_version.py"
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["src/pymetrix_eviews"]
@@ -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"]