# el-bid/armonizacion_microdatos_encuestas_hogares_scl architecture

> Architecture diagram of the GitHub repository el-bid/armonizacion_microdatos_encuestas_hogares_scl, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl
- Repository: https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl

## Overview

1. **What this repository is**
   - This is not an application runtime; it is a **Stata-based ETL/codebase** for harmonizing household survey microdata across Latin America and the Caribbean.
   - The main output is one standardized microdata file per country-year/round, designed to be comparable across time and across countries.

2. **Top-level architectural boundary**
   - The repository is organized first by **country ISO code** and then by **survey family**.
   - Each survey family is a separate transformation pipeline because the source questionnaires, file layouts, and naming conventions differ by country and by survey round.

3. **Core processing units**
   - Inside each `.../program` folder there are typically two active scripts per round:
     - `*_mergeBID.do`: combines source modules and, in some cases, multiple months/trimesters into a single working dataset.
     - `*_variablesBID.do`: creates the harmonized variables from that merged dataset.
   - These two scripts are the primary transformation stages in the repo.

4. **Data flow through the pipeline**
   - The flow is generally:
     - national survey source files/modules
     - country-specific merge routine
     - one consolidated working file
     - standardized variable construction
     - harmonized microdata dataset
   - The README indicates that intermediate merged datasets are written outside the repo to the IDB survey share, `\\sdssrv03\surveys`.

5. **Shared orchestration and cross-cutting logic**
   - `_DOCS` contains repo-wide support scripts rather than country pipelines.
   - The most important ones are:
     - `CorreDoFilesArmonizacion.do`: orchestrates running harmonization across countries.
     - `Labels&ExternalVars_Harmonized_DataBank.do`: applies shared post-processing such as labels and external inputs.

6. **External dependencies and data interfaces**
   - The repo depends on a **local Stata setup** and a user-specific `profile.do` in Stata’s `PERSONAL` directory to define paths like the Git root and survey storage root.
   - The harmonization scripts are therefore tied to local execution context, not a containerized or server-hosted environment.
   - The main external storage boundary is the shared survey server; the companion repo for indicators is a downstream consumer of the harmonized microdata.

7. **Country/survey heterogeneity as a design feature**
   - The structure reflects many survey programs: labor force surveys, household income/expenditure surveys, living standards surveys, etc.
   - Some countries have several survey families under the same country folder, and some rounds have special-case scripts, renamed files, or multi-stage merges, which indicates the pipelines are intentionally customized rather than generic.

8. **Legacy and compatibility layers**
   - Many folders contain `bak.stunicode`, `OLD`, `_old`, or version-suffixed scripts.
   - These are archival/compatibility copies of prior transformations, showing that the repository preserves historical logic for older survey rounds while newer scripts remain alongside them.

9. **Specialized subpipelines**
   - A few areas go beyond the simple merge/variables pattern:
     - `Z_LAC_Ingreso_Gasto` contains income/expenditure survey harmonization scripts across multiple countries.
     - Some country folders include deeper helper scripts for module-specific handling, data reshaping, or survey-round exceptions.
   - These are still Stata pipelines, but with more granular preprocessing steps.

10. **Repository-level purpose for diagramming**
   - The key diagram should show a **many-to-one structure**: many country/survey-specific ingestion pipelines feeding a common harmonization standard.
   - The main shared boundary is between:
     - source-specific survey files and merge logic on one side
     - standardized variable generation, labels, and external adjustments on the other
   - The output is a harmonized microdata bank that is later used by a separate indicators repository.

11. **Operational workflow**
   - The README defines a branching model with `master`, `development`, and feature branches, but this is a governance workflow rather than runtime architecture.
   - It matters because harmonization changes are expected to be reviewed centrally before landing in the stable branch used for production runs.

12. **What is intentionally not in the repo**
   - The repository does not store the raw survey source data itself.
   - It also does not compute final indicators; that work is explicitly delegated to the separate indicators repository.
   - This repo is therefore the **microdata harmonization layer** in the overall ecosystem.

Main entry points: [`_DOCS/CorreDoFilesArmonizacion.do`](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/_DOCS/CorreDoFilesArmonizacion.do) (Run all), [`ARG/EPHC/program/ARG_2022s2_mergeBID.do`](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/ARG/EPHC/program/ARG_2022s2_mergeBID.do) (ARG merge), [`ARG/EPHP/program/ARG_2003m5_mergeBID.do`](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/ARG/EPHP/program/ARG_2003m5_mergeBID.do) (ARG labor merge), [`Z_LAC_Ingreso_Gasto/BRA/POF/program/BRA_POF_2008-2009.do`](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/Z_LAC_Ingreso_Gasto/BRA/POF/program/BRA_POF_2008-2009.do) (LAC spending)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shared["Shared orchestration"]
  node_docs_orchestrator["Run all<br/>Stata orchestration"]
  node_docs_postprocess["Post-process<br/>Stata labels"]
  node_docs_model["Template<br/>Stata model<br/>[DOfile_MODELO.do]"]
  node_docs_directorio["Paths<br/>Stata path setup"]
end

subgraph group_country_pipelines["Country pipelines"]
  node_arg_ephc_merge["ARG merge<br/>survey merge"]
  node_arg_ephc_vars["ARG vars<br/>harmonization vars"]
  node_arg_ephp_merge["ARG labor merge<br/>survey merge"]
  node_arg_ephp_vars["ARG labor vars<br/>harmonization vars"]
  node_bra_pnadc["PNADC<br/>country pipeline"]
  node_bra_pme["PME<br/>country pipeline"]
  node_col_geih["GEIH<br/>country pipeline"]
  node_col_ech["ECH<br/>survey family"]
  node_cri_enaho["ENAHO<br/>survey family"]
  node_hnd_ephpm["EPHPM<br/>survey family"]
  node_mex_enoe["ENOE<br/>survey pipeline"]
  node_per_enaho["ENAHO<br/>survey family"]
  node_ury_ech["ECH<br/>survey family"]
  node_ven_ehm["EHM<br/>survey family"]
end

subgraph group_income_gasto["Income & expenditure"]
  node_lac_ingreso_gasto["LAC spending<br/>specialized pipelines"]
end

subgraph group_external["External interfaces"]
  node_per_microdata_bank[("Microdata bank<br/>harmonized output")]
  node_survey_share[("Survey share<br/>external storage")]
  node_stata_profile["Stata profile<br/>local setup"]
  node_indicators_repo["Indicators repo<br/>downstream consumer"]
end

node_docs_directorio -->|"uses paths"| node_stata_profile
node_docs_orchestrator -->|"runs"| node_arg_ephc_merge
node_docs_orchestrator -->|"runs"| node_bra_pnadc
node_docs_orchestrator -->|"runs"| node_col_geih
node_docs_orchestrator -->|"runs"| node_cri_enaho
node_docs_orchestrator -->|"runs"| node_mex_enoe
node_docs_orchestrator -->|"runs"| node_per_enaho
node_docs_orchestrator -->|"runs"| node_ven_ehm
node_arg_ephc_merge -->|"writes temp"| node_survey_share
node_arg_ephc_merge -->|"feeds"| node_arg_ephc_vars
node_arg_ephc_vars -->|"publishes"| node_per_microdata_bank
node_arg_ephp_merge -->|"writes temp"| node_survey_share
node_arg_ephp_merge -->|"feeds"| node_arg_ephp_vars
node_arg_ephp_vars -->|"publishes"| node_per_microdata_bank
node_bra_pnadc -->|"writes temp"| node_survey_share
node_bra_pme -->|"writes temp"| node_survey_share
node_col_geih -->|"writes temp"| node_survey_share
node_col_ech -->|"writes temp"| node_survey_share
node_cri_enaho -->|"writes temp"| node_survey_share
node_hnd_ephpm -->|"writes temp"| node_survey_share
node_mex_enoe -->|"writes temp"| node_survey_share
node_per_enaho -->|"writes temp"| node_survey_share
node_ury_ech -->|"writes temp"| node_survey_share
node_ven_ehm -->|"writes temp"| node_survey_share
node_docs_postprocess -->|"refines"| node_per_microdata_bank
node_lac_ingreso_gasto -->|"writes temp"| node_survey_share
node_lac_ingreso_gasto -->|"publishes"| node_per_microdata_bank
node_per_microdata_bank -->|"consumed by"| node_indicators_repo

click node_docs_orchestrator "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/_DOCS/CorreDoFilesArmonizacion.do"
click node_docs_postprocess "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/_DOCS/Labels&ExternalVars_Harmonized_DataBank.do"
click node_docs_model "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/_DOCS/DOfile_MODELO.do"
click node_docs_directorio "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/_DOCS/Directorio HS LAC.do"
click node_arg_ephc_merge "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/ARG/EPHC/program/ARG_2022s2_mergeBID.do"
click node_arg_ephc_vars "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/ARG/EPHC/program/ARG_2022s2_variablesBID.do"
click node_arg_ephp_merge "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/ARG/EPHP/program/ARG_2003m5_mergeBID.do"
click node_arg_ephp_vars "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/ARG/EPHP/program/ARG_2003m5_variablesBID.do"
click node_bra_pnadc "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/BRA/PNADC/program/BRA_2022a_variablesBID.do"
click node_bra_pme "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/BRA/PME/program/BRA_2001a_variablesBID.do"
click node_col_geih "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/COL/GEIH/program/COL_2021t3_variablesBID.do"
click node_col_ech "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/COL/ECH/program/COL_2005t3_variablesBID.do"
click node_cri_enaho "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/CRI/ENAHO/program/CRI_2022m7_variablesBID.do"
click node_hnd_ephpm "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/HND/EPHPM/program/HND_2019m6_variablesBID.do"
click node_mex_enoe "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/MEX/ENOE/program/MEX_2019t2_variablesBID.do"
click node_per_enaho "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/PER/ENAHO/program/PER_2022a_variablesBID.do"
click node_ury_ech "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/URY/ECH/program/URY_2022a_variablesBID.do"
click node_ven_ehm "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/VEN/EHM/program/VEN_2015s2_variablesBID.do"
click node_lac_ingreso_gasto "https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/Z_LAC_Ingreso_Gasto/BRA/POF/program/BRA_POF_2008-2009.do"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_docs_orchestrator,node_docs_postprocess,node_docs_model,node_docs_directorio toneBlue
class node_arg_ephc_merge,node_arg_ephc_vars,node_arg_ephp_merge,node_arg_ephp_vars,node_bra_pnadc,node_bra_pme,node_col_geih,node_col_ech,node_cri_enaho,node_hnd_ephpm,node_mex_enoe,node_per_enaho,node_ury_ech,node_ven_ehm toneAmber
class node_lac_ingreso_gasto toneMint
class node_per_microdata_bank,node_survey_share,node_stata_profile,node_indicators_repo toneRose
```

## Components

### Shared orchestration

Repo-wide Stata automation, labeling, and documentation support.

- [Run all](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/_DOCS/CorreDoFilesArmonizacion.do): Stata orchestration · Central script for running harmonization across countries. · `_DOCS/CorreDoFilesArmonizacion.do`
- [Post-process](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/_DOCS/Labels&ExternalVars_Harmonized_DataBank.do): Stata labels · Applies shared labels and external variables after harmonization. · `_DOCS/Labels&ExternalVars_Harmonized_DataBank.do`
- [Template](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/_DOCS/DOfile_MODELO.do): Stata model · Representative harmonization template used in documentation/support. · `_DOCS/DOfile_MODELO.do`
- [Paths](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/HEAD/_DOCS/Directorio%20HS%20LAC.do): Stata path setup · Defines repository and survey directory conventions for local runs. · `_DOCS/Directorio HS LAC.do`

### Country pipelines

Country- and survey-specific harmonization pipelines.

- [ARG merge](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/ARG/EPHC/program/ARG_2022s2_mergeBID.do): survey merge · EPHC source-module and period consolidation for Argentina. · `ARG/EPHC/program/ARG_2022s2_mergeBID.do`
- [ARG vars](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/ARG/EPHC/program/ARG_2022s2_variablesBID.do): harmonization vars · Builds standardized EPHC variables from merged Argentina data. · `ARG/EPHC/program/ARG_2022s2_variablesBID.do`
- [ARG labor merge](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/ARG/EPHP/program/ARG_2003m5_mergeBID.do): survey merge · Labor-force source consolidation for Argentina EPHP. · `ARG/EPHP/program/ARG_2003m5_mergeBID.do`
- [ARG labor vars](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/ARG/EPHP/program/ARG_2003m5_variablesBID.do): harmonization vars · Creates harmonized labor variables for Argentina EPHP. · `ARG/EPHP/program/ARG_2003m5_variablesBID.do`
- [PNADC](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/BRA/PNADC/program/BRA_2022a_variablesBID.do): country pipeline · Brazil continuous household survey pipeline with annual and quarterly rounds. · `BRA/PNADC/program/BRA_2022a_variablesBID.do`
- [PME](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/BRA/PME/program/BRA_2001a_variablesBID.do): country pipeline · Brazil monthly labor survey harmonization, including auxiliary subflows. · `BRA/PME/program/BRA_2001a_variablesBID.do`
- [GEIH](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/COL/GEIH/program/COL_2021t3_variablesBID.do): country pipeline · Colombia labor survey pipeline with specialized multi-module merges. · `COL/GEIH/program/COL_2021t3_variablesBID.do`
- [ECH](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/COL/ECH/program/COL_2005t3_variablesBID.do): survey family · Older Colombia household survey harmonization family. · `COL/ECH/program/COL_2005t3_variablesBID.do`
- [ENAHO](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/CRI/ENAHO/program/CRI_2022m7_variablesBID.do): survey family · Costa Rica household survey harmonization pipeline. · `CRI/ENAHO/program/CRI_2022m7_variablesBID.do`
- [EPHPM](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/HND/EPHPM/program/HND_2019m6_variablesBID.do): survey family · Honduras household survey pipeline with legacy MDG-related extras. · `HND/EPHPM/program/HND_2019m6_variablesBID.do`
- [ENOE](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/MEX/ENOE/program/MEX_2019t2_variablesBID.do): survey pipeline · Mexico labor-force survey harmonization across quarterly rounds. · `MEX/ENOE/program/MEX_2019t2_variablesBID.do`
- [ENAHO](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/PER/ENAHO/program/PER_2022a_variablesBID.do): survey family · Peru household survey pipeline with annual harmonization rounds. · `PER/ENAHO/program/PER_2022a_variablesBID.do`
- [ECH](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/URY/ECH/program/URY_2022a_variablesBID.do): survey family · Uruguay household survey harmonization family. · `URY/ECH/program/URY_2022a_variablesBID.do`
- [EHM](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/VEN/EHM/program/VEN_2015s2_variablesBID.do): survey family · Venezuela household survey harmonization pipeline. · `VEN/EHM/program/VEN_2015s2_variablesBID.do`

### Income & expenditure

Cross-country specialized consumption/income harmonization area.

- [LAC spending](https://github.com/el-bid/armonizacion_microdatos_encuestas_hogares_scl/blob/master/Z_LAC_Ingreso_Gasto/BRA/POF/program/BRA_POF_2008-2009.do): specialized pipelines · Cross-country income and expenditure harmonization area. · `Z_LAC_Ingreso_Gasto/BRA/POF/program/BRA_POF_2008-2009.do`

### External interfaces

Local Stata setup and survey-storage boundary outside the repository.

- **Microdata bank**: harmonized output · Standardized comparable household microdata used downstream.
- **Survey share**: external storage · Intermediate working datasets and shared survey storage outside the repo.
- **Stata profile**: local setup · User-specific Stata PERSONAL profile that defines local paths.
- **Indicators repo**: downstream consumer · Separate repository that consumes harmonized microdata to compute indicators.

## Connections

- Paths → Stata profile: uses paths · Local path resolution depends on user Stata configuration.
- Run all → ARG merge: runs · Coordinates country harmonization jobs.
- Run all → PNADC: runs · Coordinates country harmonization jobs.
- Run all → GEIH: runs · Coordinates country harmonization jobs.
- Run all → ENAHO: runs · Coordinates country harmonization jobs.
- Run all → ENOE: runs · Coordinates country harmonization jobs.
- Run all → ENAHO: runs · Coordinates country harmonization jobs.
- Run all → EHM: runs · Coordinates country harmonization jobs.
- ARG merge → Survey share: writes temp · Merged working files are written to shared survey storage.
- ARG merge → ARG vars: feeds · Merged survey data becomes input to harmonized variable construction.
- ARG vars → Microdata bank: publishes · Produces standardized microdata for downstream use.
- ARG labor merge → Survey share: writes temp · Merged working files are written outside the repo.
- ARG labor merge → ARG labor vars: feeds · Merged labor data becomes input to harmonized variable construction.
- ARG labor vars → Microdata bank: publishes · Produces standardized labor microdata.
- PNADC → Survey share: writes temp · Intermediate merged datasets are stored externally.
- PME → Survey share: writes temp · Intermediate merged datasets are stored externally.
- GEIH → Survey share: writes temp · Specialized multi-module merges land in shared storage.
- ECH → Survey share: writes temp · Survey-family processing uses external working storage.
- ENAHO → Survey share: writes temp · Intermediate files are held outside the repository.
- EPHPM → Survey share: writes temp · Intermediate files are held outside the repository.
- ENOE → Survey share: writes temp · Intermediate files are held outside the repository.
- ENAHO → Survey share: writes temp · Intermediate files are held outside the repository.
- ECH → Survey share: writes temp · Intermediate files are held outside the repository.
- EHM → Survey share: writes temp · Intermediate files are held outside the repository.
- Post-process → Microdata bank: refines · Applies shared labels and external inputs to the harmonized bank.
- LAC spending → Survey share: writes temp · Specialized income/expenditure harmonization also uses external working storage.
- LAC spending → Microdata bank: publishes · Contributes specialized harmonized microdata to the bank.
- Microdata bank → Indicators repo: consumed by · Downstream indicators repository consumes harmonized microdata.
