perudata 0.1.1__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.
- perudata-0.1.1/.github/probe_new_year.py +62 -0
- perudata-0.1.1/.github/workflows/watch-new-year.yml +31 -0
- perudata-0.1.1/.gitignore +9 -0
- perudata-0.1.1/LICENSE +21 -0
- perudata-0.1.1/PKG-INFO +170 -0
- perudata-0.1.1/README.md +149 -0
- perudata-0.1.1/examples/poverty_replication.py +14 -0
- perudata-0.1.1/pyproject.toml +35 -0
- perudata-0.1.1/src/perudata/__init__.py +19 -0
- perudata-0.1.1/src/perudata/_core.py +220 -0
- perudata-0.1.1/src/perudata/catalogs/eea_catalog.csv +605 -0
- perudata-0.1.1/src/perudata/catalogs/epen_catalog.csv +280 -0
- perudata-0.1.1/src/perudata/cli.py +79 -0
- perudata-0.1.1/src/perudata/eea.py +137 -0
- perudata-0.1.1/src/perudata/enaho.py +213 -0
- perudata-0.1.1/src/perudata/endes.py +176 -0
- perudata-0.1.1/src/perudata/epen.py +136 -0
- perudata-0.1.1/src/perudata/panel.py +261 -0
- perudata-0.1.1/src/perudata/validate.py +80 -0
- perudata-0.1.1/tests/test_offline.py +89 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""CI probe: is there an ENAHO proyecto code newer than the ones we map?
|
|
2
|
+
|
|
3
|
+
Scans a window above the highest known code for a live Modulo34 zip. On a hit
|
|
4
|
+
it opens a GitHub issue (once — skips codes already reported) so a maintainer
|
|
5
|
+
can content-verify the internal `año` and add one line to enaho.YEAR_CODE.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import subprocess
|
|
11
|
+
|
|
12
|
+
from perudata import enaho
|
|
13
|
+
|
|
14
|
+
WINDOW = 120
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def existing_issue_codes() -> set[int]:
|
|
18
|
+
try:
|
|
19
|
+
out = subprocess.run(
|
|
20
|
+
["gh", "issue", "list", "--label", "new-inei-year", "--state", "all",
|
|
21
|
+
"--json", "title"], capture_output=True, text=True, check=True).stdout
|
|
22
|
+
codes = set()
|
|
23
|
+
for it in json.loads(out or "[]"):
|
|
24
|
+
for tok in it["title"].split():
|
|
25
|
+
if tok.isdigit():
|
|
26
|
+
codes.add(int(tok))
|
|
27
|
+
return codes
|
|
28
|
+
except Exception:
|
|
29
|
+
return set()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def main() -> None:
|
|
33
|
+
top = max(enaho.YEAR_CODE.values())
|
|
34
|
+
print(f"probing codes {top + 1}..{top + WINDOW} (newest mapped: "
|
|
35
|
+
f"{enaho.latest_year()} = {top})")
|
|
36
|
+
hits = enaho.discover(0, lo=top + 1, hi=top + WINDOW)
|
|
37
|
+
if not hits:
|
|
38
|
+
print("no new codes on the INEI server")
|
|
39
|
+
return
|
|
40
|
+
known = existing_issue_codes()
|
|
41
|
+
fresh = [c for c in hits if c not in known]
|
|
42
|
+
if not fresh:
|
|
43
|
+
print(f"codes {hits} already reported")
|
|
44
|
+
return
|
|
45
|
+
body = (
|
|
46
|
+
f"The INEI server answers 200 for Modulo34 at proyecto code(s) **{fresh}** — "
|
|
47
|
+
f"likely ENAHO {enaho.latest_year() + 1}.\n\n"
|
|
48
|
+
"Next steps:\n"
|
|
49
|
+
"1. download it and read the internal `año` variable (codes are NOT chronological)\n"
|
|
50
|
+
"2. add the verified line to `enaho.YEAR_CODE`\n"
|
|
51
|
+
"3. run `perudata validate` for the new year against INEI's published poverty\n"
|
|
52
|
+
)
|
|
53
|
+
subprocess.run(
|
|
54
|
+
["gh", "issue", "create",
|
|
55
|
+
"--title", f"New ENAHO proyecto code(s) live: {' '.join(map(str, fresh))}",
|
|
56
|
+
"--label", "new-inei-year", "--body", body],
|
|
57
|
+
check=True)
|
|
58
|
+
print(f"issue created for {fresh}")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if __name__ == "__main__":
|
|
62
|
+
main()
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Watch INEI for a new ENAHO year
|
|
2
|
+
|
|
3
|
+
# INEI publishes each new ENAHO year as a fresh proyecto code with no
|
|
4
|
+
# announcement API. This probes the code range above the newest mapped year
|
|
5
|
+
# every Monday and opens an issue the day a new Modulo34 appears.
|
|
6
|
+
on:
|
|
7
|
+
schedule:
|
|
8
|
+
- cron: "0 12 * * 1"
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
issues: write
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
probe:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
- run: pip install -e .
|
|
24
|
+
- name: Ensure label exists
|
|
25
|
+
env:
|
|
26
|
+
GH_TOKEN: ${{ github.token }}
|
|
27
|
+
run: gh label create new-inei-year --force --color 0e8a16 --description "INEI published a new survey year" || true
|
|
28
|
+
- name: Probe unmapped proyecto codes
|
|
29
|
+
env:
|
|
30
|
+
GH_TOKEN: ${{ github.token }}
|
|
31
|
+
run: python .github/probe_new_year.py
|
perudata-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Carlos Chávez Padilla
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
perudata-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: perudata
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Peru's official INEI microdata (ENAHO, ENDES, EPEN, EEA, ENAHO Panel): download, load and validate against official statistics
|
|
5
|
+
Project-URL: Homepage, https://github.com/cesarchavezp29/perudata
|
|
6
|
+
Project-URL: Issues, https://github.com/cesarchavezp29/perudata/issues
|
|
7
|
+
Author-email: Carlos Chávez Padilla <cesarchavezpadilla@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: dhs,economics,enaho,endes,inei,microdata,peru,poverty,survey
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering
|
|
16
|
+
Classifier: Topic :: Sociology
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Requires-Dist: pandas>=1.5
|
|
19
|
+
Requires-Dist: pyreadstat>=1.2
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# perudata
|
|
23
|
+
|
|
24
|
+
**Peru's official INEI microdata, one import away.**
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from perudata import enaho, validate
|
|
28
|
+
|
|
29
|
+
df = enaho.load(2024, "34") # ENAHO sumaria: income, spending, poverty
|
|
30
|
+
validate.poverty(years=[2024]) # reproduces INEI's official 27.6% from raw data
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Five national surveys, one consistent API. Every file is verified on download
|
|
34
|
+
by actually opening it, and a built-in validation gate reproduces INEI's
|
|
35
|
+
official poverty series **to 0.0 percentage points, 2004–2025** before you
|
|
36
|
+
build anything on top.
|
|
37
|
+
|
|
38
|
+
| Survey | What it is | Coverage | Format |
|
|
39
|
+
|---|---|---|---|
|
|
40
|
+
| `enaho` | ENAHO — national household survey (income, poverty, employment, education, health, governance) | 2004–2025, 29 modules | Stata |
|
|
41
|
+
| `panel` | ENAHO Panel — same households re-interviewed (true poverty dynamics, FE) | 10 releases, 2007–2023 | Stata |
|
|
42
|
+
| `endes` | ENDES — Peru's DHS (fertility, child health, anemia, domestic violence) | 1996–2024 | SPSS |
|
|
43
|
+
| `epen` | EPE/EPEN — permanent employment surveys (Lima monthly since 2001, national) | 279 verified datasets | CSV |
|
|
44
|
+
| `eea` | EEA — annual economic survey of firms (sales, assets, employment, CIIU) | 2001–2024, 604 datasets | CSV |
|
|
45
|
+
|
|
46
|
+
## Install
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install perudata # once published; for now:
|
|
50
|
+
pip install git+https://github.com/cesarchavezp29/perudata
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Requires Python ≥ 3.9. Dependencies: `pandas`, `pyreadstat`.
|
|
54
|
+
|
|
55
|
+
## Quickstart
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from perudata import enaho, endes, epen, eea, panel, validate
|
|
59
|
+
|
|
60
|
+
# --- ENAHO (annual cross-section) ------------------------------------------
|
|
61
|
+
enaho.years() # [2004, ..., 2025]
|
|
62
|
+
enaho.modules() # DataFrame of the 29 modules
|
|
63
|
+
enaho.download([2023, 2024], ["01", "34", "85"])
|
|
64
|
+
df = enaho.load(2024, "34") # auto-downloads if missing
|
|
65
|
+
|
|
66
|
+
# national poverty, the official INEI way (person = factor07 x mieperho):
|
|
67
|
+
w = df["factor07"] * df["mieperho"]
|
|
68
|
+
poverty = 100 * w[df["pobreza"].isin([1, 2])].sum() / w.sum() # -> 27.6
|
|
69
|
+
|
|
70
|
+
# --- validation gate ---------------------------------------------------------
|
|
71
|
+
validate.poverty() # full 2004-2025 table vs official INEI
|
|
72
|
+
|
|
73
|
+
# --- ENAHO Panel (longitudinal) ----------------------------------------------
|
|
74
|
+
panel.releases() # [2011, 2015, ..., 2022, 2023] — 10 releases
|
|
75
|
+
df, meta = panel.load_long(2023, "sumaria") # latest: 2019-2023, tidy long
|
|
76
|
+
meta["waves"] # [2019, 2020, 2021, 2022, 2023]
|
|
77
|
+
# any release works the same, e.g. the earliest 5-year panel:
|
|
78
|
+
df, meta = panel.load_long(2011, "sumaria") # 2007-2011
|
|
79
|
+
|
|
80
|
+
# --- ENDES (DHS) --------------------------------------------------------------
|
|
81
|
+
endes.download(2024, ["peso_talla_anemia"])
|
|
82
|
+
kids = endes.load(2024, "peso_talla_anemia")
|
|
83
|
+
|
|
84
|
+
# --- EPEN (employment) ---------------------------------------------------------
|
|
85
|
+
epen.search("lima") # find datasets in the verified catalog
|
|
86
|
+
df = epen.load(997) # download + read by catalog code
|
|
87
|
+
|
|
88
|
+
# --- EEA (firms) ----------------------------------------------------------------
|
|
89
|
+
eea.modules(2024) # sector modules of EEA 2024
|
|
90
|
+
df = eea.load(eea.modules(2024)["csv_code"].iloc[0])
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Or from the command line:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
perudata enaho --years 2024 --modules 01 34
|
|
97
|
+
perudata validate --years 2024
|
|
98
|
+
perudata epen --search "dpto 2024"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Where files go
|
|
102
|
+
|
|
103
|
+
Everything lands under `./peru_raw` (override per call with `out=` or globally
|
|
104
|
+
with the `PERUDATA_DIR` environment variable), named so you always know what a
|
|
105
|
+
file is:
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
peru_raw/
|
|
109
|
+
enaho/sumaria/enaho-2024-34.dta
|
|
110
|
+
enaho_panel/2011_302/panel-2011-sumaria.dta
|
|
111
|
+
endes/2024_968/1629_hogar/968-Modulo1629/*.sav
|
|
112
|
+
epen/804_15_lima.../*.csv
|
|
113
|
+
eea/987-Modulo1968/a2022_s04_fF2/*.csv
|
|
114
|
+
*/_manifest.csv # what was downloaded, when, rows x cols
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Downloads are **idempotent**: a file that exists and verified is skipped, so
|
|
118
|
+
you can re-run a script after adding years and only the new ones are fetched.
|
|
119
|
+
|
|
120
|
+
## Why this exists
|
|
121
|
+
|
|
122
|
+
INEI publishes superb microdata, but using it programmatically means knowing
|
|
123
|
+
a pile of undocumented conventions, all of which this package encodes:
|
|
124
|
+
|
|
125
|
+
- Each survey-year is a numbered *proyecto* (`1031-Modulo34.zip`), and the
|
|
126
|
+
codes are **not chronological** — code 279 is 2010 while 280–285 are
|
|
127
|
+
2004–2009. Every ENAHO code here was verified by reading the internal `año`
|
|
128
|
+
variable of its file.
|
|
129
|
+
- ENAHO 2004–2011 ships **Stata 7 (v110)** files that pandas cannot read —
|
|
130
|
+
`load()` falls back to pyreadstat transparently.
|
|
131
|
+
- Sumaria zips carry `-12`/`-12g` alternates that silently lack the poverty
|
|
132
|
+
variables. The canonical file is selected for you.
|
|
133
|
+
- ENDES exists **only in SPSS** for the full 1996–2024 series, and its module
|
|
134
|
+
numbers were renumbered in 2020 (64–74 → 1629–1641).
|
|
135
|
+
- The ENAHO Panel changed module numbering in 2018 (01/34 → 1474–1479) and old
|
|
136
|
+
releases are WIDE files; `panel.load_long()` returns a tidy long panel
|
|
137
|
+
either way.
|
|
138
|
+
- EPEN and EEA are CSV-only with no year→code formula at all — the package
|
|
139
|
+
ships verified catalogs (279 and 604 datasets) discovered by probing the
|
|
140
|
+
server and opening every file.
|
|
141
|
+
|
|
142
|
+
## Validation
|
|
143
|
+
|
|
144
|
+
`validate.poverty()` recomputes national monetary poverty from the raw sumaria
|
|
145
|
+
(person-weighted, `factor07 × mieperho`, `pobreza ∈ {1,2}`) and compares it to
|
|
146
|
+
the official series from INEI's *Evolución de la Pobreza Monetaria* reports:
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
year poverty_pct official_poverty pov_diff
|
|
150
|
+
2004 58.7 58.7 0.0
|
|
151
|
+
...
|
|
152
|
+
2024 27.6 27.6 0.0
|
|
153
|
+
2025 25.7 25.7 0.0
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
22/22 years within 0.1pp (0.0pp in every year, extreme poverty included where
|
|
157
|
+
published).
|
|
158
|
+
|
|
159
|
+
## Notes
|
|
160
|
+
|
|
161
|
+
- Data © INEI (Instituto Nacional de Estadística e Informática del Perú),
|
|
162
|
+
published as open microdata. This package only automates download and
|
|
163
|
+
reading — cite INEI and the survey when you publish.
|
|
164
|
+
- Value labels are not applied on load; you get the raw codes exactly as INEI
|
|
165
|
+
documents them (the PDFs inside each zip are kept for EPEN/EEA).
|
|
166
|
+
- New ENAHO year out? `enaho.discover(2026)` scans the server for its code.
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT — see [LICENSE](LICENSE). Built by [Carlos Chávez Padilla](https://github.com/cesarchavezp29).
|
perudata-0.1.1/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# perudata
|
|
2
|
+
|
|
3
|
+
**Peru's official INEI microdata, one import away.**
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
from perudata import enaho, validate
|
|
7
|
+
|
|
8
|
+
df = enaho.load(2024, "34") # ENAHO sumaria: income, spending, poverty
|
|
9
|
+
validate.poverty(years=[2024]) # reproduces INEI's official 27.6% from raw data
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Five national surveys, one consistent API. Every file is verified on download
|
|
13
|
+
by actually opening it, and a built-in validation gate reproduces INEI's
|
|
14
|
+
official poverty series **to 0.0 percentage points, 2004–2025** before you
|
|
15
|
+
build anything on top.
|
|
16
|
+
|
|
17
|
+
| Survey | What it is | Coverage | Format |
|
|
18
|
+
|---|---|---|---|
|
|
19
|
+
| `enaho` | ENAHO — national household survey (income, poverty, employment, education, health, governance) | 2004–2025, 29 modules | Stata |
|
|
20
|
+
| `panel` | ENAHO Panel — same households re-interviewed (true poverty dynamics, FE) | 10 releases, 2007–2023 | Stata |
|
|
21
|
+
| `endes` | ENDES — Peru's DHS (fertility, child health, anemia, domestic violence) | 1996–2024 | SPSS |
|
|
22
|
+
| `epen` | EPE/EPEN — permanent employment surveys (Lima monthly since 2001, national) | 279 verified datasets | CSV |
|
|
23
|
+
| `eea` | EEA — annual economic survey of firms (sales, assets, employment, CIIU) | 2001–2024, 604 datasets | CSV |
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install perudata # once published; for now:
|
|
29
|
+
pip install git+https://github.com/cesarchavezp29/perudata
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Requires Python ≥ 3.9. Dependencies: `pandas`, `pyreadstat`.
|
|
33
|
+
|
|
34
|
+
## Quickstart
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from perudata import enaho, endes, epen, eea, panel, validate
|
|
38
|
+
|
|
39
|
+
# --- ENAHO (annual cross-section) ------------------------------------------
|
|
40
|
+
enaho.years() # [2004, ..., 2025]
|
|
41
|
+
enaho.modules() # DataFrame of the 29 modules
|
|
42
|
+
enaho.download([2023, 2024], ["01", "34", "85"])
|
|
43
|
+
df = enaho.load(2024, "34") # auto-downloads if missing
|
|
44
|
+
|
|
45
|
+
# national poverty, the official INEI way (person = factor07 x mieperho):
|
|
46
|
+
w = df["factor07"] * df["mieperho"]
|
|
47
|
+
poverty = 100 * w[df["pobreza"].isin([1, 2])].sum() / w.sum() # -> 27.6
|
|
48
|
+
|
|
49
|
+
# --- validation gate ---------------------------------------------------------
|
|
50
|
+
validate.poverty() # full 2004-2025 table vs official INEI
|
|
51
|
+
|
|
52
|
+
# --- ENAHO Panel (longitudinal) ----------------------------------------------
|
|
53
|
+
panel.releases() # [2011, 2015, ..., 2022, 2023] — 10 releases
|
|
54
|
+
df, meta = panel.load_long(2023, "sumaria") # latest: 2019-2023, tidy long
|
|
55
|
+
meta["waves"] # [2019, 2020, 2021, 2022, 2023]
|
|
56
|
+
# any release works the same, e.g. the earliest 5-year panel:
|
|
57
|
+
df, meta = panel.load_long(2011, "sumaria") # 2007-2011
|
|
58
|
+
|
|
59
|
+
# --- ENDES (DHS) --------------------------------------------------------------
|
|
60
|
+
endes.download(2024, ["peso_talla_anemia"])
|
|
61
|
+
kids = endes.load(2024, "peso_talla_anemia")
|
|
62
|
+
|
|
63
|
+
# --- EPEN (employment) ---------------------------------------------------------
|
|
64
|
+
epen.search("lima") # find datasets in the verified catalog
|
|
65
|
+
df = epen.load(997) # download + read by catalog code
|
|
66
|
+
|
|
67
|
+
# --- EEA (firms) ----------------------------------------------------------------
|
|
68
|
+
eea.modules(2024) # sector modules of EEA 2024
|
|
69
|
+
df = eea.load(eea.modules(2024)["csv_code"].iloc[0])
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Or from the command line:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
perudata enaho --years 2024 --modules 01 34
|
|
76
|
+
perudata validate --years 2024
|
|
77
|
+
perudata epen --search "dpto 2024"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Where files go
|
|
81
|
+
|
|
82
|
+
Everything lands under `./peru_raw` (override per call with `out=` or globally
|
|
83
|
+
with the `PERUDATA_DIR` environment variable), named so you always know what a
|
|
84
|
+
file is:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
peru_raw/
|
|
88
|
+
enaho/sumaria/enaho-2024-34.dta
|
|
89
|
+
enaho_panel/2011_302/panel-2011-sumaria.dta
|
|
90
|
+
endes/2024_968/1629_hogar/968-Modulo1629/*.sav
|
|
91
|
+
epen/804_15_lima.../*.csv
|
|
92
|
+
eea/987-Modulo1968/a2022_s04_fF2/*.csv
|
|
93
|
+
*/_manifest.csv # what was downloaded, when, rows x cols
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Downloads are **idempotent**: a file that exists and verified is skipped, so
|
|
97
|
+
you can re-run a script after adding years and only the new ones are fetched.
|
|
98
|
+
|
|
99
|
+
## Why this exists
|
|
100
|
+
|
|
101
|
+
INEI publishes superb microdata, but using it programmatically means knowing
|
|
102
|
+
a pile of undocumented conventions, all of which this package encodes:
|
|
103
|
+
|
|
104
|
+
- Each survey-year is a numbered *proyecto* (`1031-Modulo34.zip`), and the
|
|
105
|
+
codes are **not chronological** — code 279 is 2010 while 280–285 are
|
|
106
|
+
2004–2009. Every ENAHO code here was verified by reading the internal `año`
|
|
107
|
+
variable of its file.
|
|
108
|
+
- ENAHO 2004–2011 ships **Stata 7 (v110)** files that pandas cannot read —
|
|
109
|
+
`load()` falls back to pyreadstat transparently.
|
|
110
|
+
- Sumaria zips carry `-12`/`-12g` alternates that silently lack the poverty
|
|
111
|
+
variables. The canonical file is selected for you.
|
|
112
|
+
- ENDES exists **only in SPSS** for the full 1996–2024 series, and its module
|
|
113
|
+
numbers were renumbered in 2020 (64–74 → 1629–1641).
|
|
114
|
+
- The ENAHO Panel changed module numbering in 2018 (01/34 → 1474–1479) and old
|
|
115
|
+
releases are WIDE files; `panel.load_long()` returns a tidy long panel
|
|
116
|
+
either way.
|
|
117
|
+
- EPEN and EEA are CSV-only with no year→code formula at all — the package
|
|
118
|
+
ships verified catalogs (279 and 604 datasets) discovered by probing the
|
|
119
|
+
server and opening every file.
|
|
120
|
+
|
|
121
|
+
## Validation
|
|
122
|
+
|
|
123
|
+
`validate.poverty()` recomputes national monetary poverty from the raw sumaria
|
|
124
|
+
(person-weighted, `factor07 × mieperho`, `pobreza ∈ {1,2}`) and compares it to
|
|
125
|
+
the official series from INEI's *Evolución de la Pobreza Monetaria* reports:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
year poverty_pct official_poverty pov_diff
|
|
129
|
+
2004 58.7 58.7 0.0
|
|
130
|
+
...
|
|
131
|
+
2024 27.6 27.6 0.0
|
|
132
|
+
2025 25.7 25.7 0.0
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
22/22 years within 0.1pp (0.0pp in every year, extreme poverty included where
|
|
136
|
+
published).
|
|
137
|
+
|
|
138
|
+
## Notes
|
|
139
|
+
|
|
140
|
+
- Data © INEI (Instituto Nacional de Estadística e Informática del Perú),
|
|
141
|
+
published as open microdata. This package only automates download and
|
|
142
|
+
reading — cite INEI and the survey when you publish.
|
|
143
|
+
- Value labels are not applied on load; you get the raw codes exactly as INEI
|
|
144
|
+
documents them (the PDFs inside each zip are kept for EPEN/EEA).
|
|
145
|
+
- New ENAHO year out? `enaho.discover(2026)` scans the server for its code.
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
MIT — see [LICENSE](LICENSE). Built by [Carlos Chávez Padilla](https://github.com/cesarchavezp29).
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Reproduce INEI's official national poverty series from raw ENAHO microdata.
|
|
3
|
+
|
|
4
|
+
Downloads the sumaria (module 34) for the requested years into ./peru_raw and
|
|
5
|
+
prints computed vs official poverty. Expect 0.0pp differences.
|
|
6
|
+
|
|
7
|
+
python examples/poverty_replication.py 2022 2023 2024
|
|
8
|
+
"""
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
from perudata import validate
|
|
12
|
+
|
|
13
|
+
years = [int(y) for y in sys.argv[1:]] or [2023, 2024, 2025]
|
|
14
|
+
validate.poverty(years=years)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "perudata"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Peru's official INEI microdata (ENAHO, ENDES, EPEN, EEA, ENAHO Panel): download, load and validate against official statistics"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
authors = [{ name = "Carlos Chávez Padilla", email = "cesarchavezpadilla@gmail.com" }]
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"pandas>=1.5",
|
|
15
|
+
"pyreadstat>=1.2",
|
|
16
|
+
]
|
|
17
|
+
keywords = ["peru", "inei", "enaho", "endes", "dhs", "microdata", "poverty", "survey", "economics"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 4 - Beta",
|
|
20
|
+
"Intended Audience :: Science/Research",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Topic :: Scientific/Engineering",
|
|
24
|
+
"Topic :: Sociology",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/cesarchavezp29/perudata"
|
|
29
|
+
Issues = "https://github.com/cesarchavezp29/perudata/issues"
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
perudata = "perudata.cli:main"
|
|
33
|
+
|
|
34
|
+
[tool.hatch.build.targets.wheel]
|
|
35
|
+
packages = ["src/perudata"]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""
|
|
2
|
+
perudata — Peru's official INEI microdata, one import away.
|
|
3
|
+
|
|
4
|
+
from perudata import enaho, endes, epen, eea, panel, validate
|
|
5
|
+
|
|
6
|
+
df = enaho.load(2024, "34") # ENAHO sumaria: income, spending, poverty
|
|
7
|
+
validate.poverty(years=[2024]) # reproduces INEI's official 27.6%
|
|
8
|
+
|
|
9
|
+
Five surveys, one consistent API (download / load / catalog), every file
|
|
10
|
+
verified on download by opening it, and a validation gate that reproduces the
|
|
11
|
+
official poverty series to 0.0pp before you build anything on top.
|
|
12
|
+
|
|
13
|
+
Data lands in ./peru_raw by default — override per call with out= or globally
|
|
14
|
+
with the PERUDATA_DIR environment variable.
|
|
15
|
+
"""
|
|
16
|
+
from . import eea, enaho, endes, epen, panel, validate # noqa: F401
|
|
17
|
+
|
|
18
|
+
__version__ = "0.1.1"
|
|
19
|
+
__all__ = ["enaho", "endes", "epen", "eea", "panel", "validate"]
|