← Back to Code & Data

Practical README

Homogeneity — Practical README

Le téléchargement ci-dessous contient les programmes, les données de simulation et les sorties. Pour reproduire les résultats numériques et les figures, extraire le dossier, puis exécuter depuis sa racine :

python -m pip install -r python/requirements.txt
python python/check_derivations.py
python python/utility_figure.py
python python/simulate_and_test.py
Rscript R/utility_figure.R
Rscript R/simulate_and_test.R

R utilise ses bibliothèques de base ; les figures peuvent utiliser ggplot2 si disponible. Exécuter Python avant R pour fournir data/sim_data.csv. Les sorties sont écrites dans output/.

Download Python/R code, data and outputs · Open the code section · Read the note

The author’s complete README follows. Its document-build commands (note/build_md.py, latexmk) and the document checks in verify_note.py use the original note/ sources, which are outside the computational download. The six commands above reproduce the computational workflow from the supplied code package. The versions and checks listed below are the author’s supplied record.

Imposing and Testing Zero-Degree Homogeneity in Demand — teaching note

Teaching note (M2/PhD) with fully reproducible Python and R code. Every number in the note is read from files produced in output/; nothing is typed by hand.

Contents

homogeneity/
├── note/
│   ├── homogeneity.tex           # article version (amsmath, booktabs, hyperref); \inputs output/*.tex
│   ├── homogeneity.pdf           # 7 pages + 1-page appendix (power figure)
│   ├── homogeneity.md            # website version (MathJax), generated by build_md.py
│   ├── homogeneity_template.md   # prose of the .md; math blocks are copied from the .tex
│   ├── build_md.py
│   └── figures/                  # PDF (LaTeX) and PNG (website)
├── python/
│   ├── check_derivations.py      # sympy: Cobb-Douglas, Stone-Geary, Euler identity, 2^0.1 - 1
│   ├── utility_figure.py         # Figure 1
│   ├── simulate_and_test.py      # simulation, estimation, tests, Monte Carlo, tables, Figures 2-4
│   ├── verify_note.py            # independent second check (numpy only) + note consistency
│   └── requirements.txt
├── R/
│   ├── utility_figure.R          # Figure 1 in base R
│   └── simulate_and_test.R       # own simulation + re-estimation on data/sim_data.csv
├── data/sim_data.csv             # written by Python, read by R (17 significant digits)
├── output/                       # tables (.tex/.md), macros, logs, cross-check, R figures
└── Makefile

Reproduce

From this folder: make, or in order

python python/check_derivations.py
python python/utility_figure.py
python python/simulate_and_test.py
Rscript R/utility_figure.R
Rscript R/simulate_and_test.R
python note/build_md.py
cd note && latexmk -pdf homogeneity.tex && cd ..
python python/verify_note.py

All parameters are at the top of simulate_and_test.py and simulate_and_test.R (seed 20261015, R = 50 regions, T = 10 periods, J = 3 goods). Full run: about 30 seconds.

Checks performed

  • Symbolic (sympy): Cobb-Douglas and Stone-Geary demands from the Lagrangian, homogeneity, closed-form elasticities, Euler sum = 0 (exactly, also at the numerical point).
  • R vs Python on the common file data/sim_data.csv: 58 quantities (coefficients, s.e., θ, t, F, p, SSR, Wald, LR); max |difference| = 2.9e-13 (tolerance 1e-6). See output/crosscheck_R_vs_Python.csv.
  • R’s own simulation vs Python’s (different RNGs): size, power and Figure-4 statistics agree within Monte Carlo error (output/log_R.txt).
  • Every displayed derivation is written once, in homogeneity.tex (marked % block:name), and copied into the .md by build_md.py; all 289 formulas of the .md compile in MathJax 3.
  • verify_note.py: 18/18 checks (hand OLS, restricted-least-squares formula, finite-difference elasticities, table cells, identical numbers in .tex and .md, page count).

Figure numbering

Files keep the numbering of the specification (fig3_power, fig4_restricted_vs_unrestricted). In the note, the power curve is in the appendix (Figure A.1), so the restricted-vs-unrestricted figure is Figure 3.

Versions used

Python 3.13.16, numpy 2.5.3, pandas 3.0.5, scipy 1.18.1, statsmodels 0.15.0, matplotlib 3.11.2, sympy 1.14.0; R 4.3.3 (base only; ggplot2 not installed, so base graphics); pdfTeX 3.141592653-2.6-1.40.25 (TeX Live 2023), latexmk 4.83, pandoc 3.1.3.