Skip to content

purnimaporwal/malawi-energy-replication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Malawi Energy Replication ⚡

RA Application Task | January 2026 Language: R

Full replication of the published Malawi energy paper in R, plus PM2.5 air quality data scraping for India: cooking fuel, household expenditure, energy prices, and women's decision-making.


What this is

In January 2026 I was given a replication task as part of an RA application. The paper was:

Aggarwal, R. and Steckel, J. C. (2025). "Electricity price hikes raise firewood consumption and women's collection time in Malawi." Environmental Research: Energy, 2, 025014. Read the paper

I had planned to use Stata, but my licence expired before I could start. So I replicated everything in R instead, learning the workflow as I went.

I replicated all four requested outputs. The code is documented throughout with notes explaining the decisions I made, where I hit problems, and how I resolved them.


What I replicated

Figure 1 — Cooking fuel choice by urban/rural residence (2019-20)

Weighted bar chart showing the distribution of household cooking fuel choices across rural and urban areas, using panel survey weights from the Malawi IHPS. The main challenge here was handling the mismatch between printed page numbers and actual survey round labels in the dataset, and fixing a typo in the original fuel label ("Puchased firewood" → "Purchased firewood").

Table A1 — Annual household expenditure (MWK), panel sample 2010-20

Summary statistics (observations, mean, SD, min, max) by survey round. I ran into a real problem here: the replication files include nominal annual expenditure but no CPI deflator or pre-constructed real expenditure variable. The observation counts match the paper but the expenditure moments differ from the published real statistics. I documented this explicitly in the code rather than trying to hide the discrepancy.

Table A2 — Energy prices by fuel type

Mean prices (MWK) by survey round for firewood, charcoal, and electricity. Required handling log-transformed price variables (converting back from ln_p using exp()) and deduplicating monthly price observations within panel rounds.

Table A7 — Women's intra-household decision-making (DHS 2015-16 Malawi)

Percentage of households where women make decisions jointly or independently across four decision types. The main challenge was mapping DHS numeric response codes to readable categories — the factor labels do not map intuitively and required careful checking.


Extra work: India air quality data

I also collected and processed PM2.5 daily average air quality data for 10 Indian cities from India's Central Pollution Control Board (CPCB) portal for 1 January 2025.

The CPCB portal uses dynamic JavaScript layers and session-based tokens that resist standard automated scraping tools like rvest. So I performed a targeted manual scrape — queried the 24-hour daily Average for 10 geographically diverse cities, extracted the verified daily mean (µg/m³) for each, and formatted it into a research-ready CSV. I then cleaned and processed it in R and computed a 10-city national average.

10-city national average PM2.5 on 1 January 2025: 91.96 µg/m³

The raw data and cleaned output are in the repository; the R script documents exactly what was done and why automated scraping was not used.

Files

malawi-energy-replication/
│
├── Figure_1.R               # Weighted cooking fuel chart (Malawi IHPS 2019-20)
├── Table_A1.R               # Annual household expenditure by survey round
├── Table_A2.R               # Energy prices by fuel type
├── Table_A7.R               # Women's decision-making (DHS 2015-16)
├── Data_Scrapping.R         # PM2.5 data processing (Section B)
│
├── Data_Scrapping/
│   └── CPCB_data(Sheet1).csv   # Raw PM2.5 data — 10 Indian cities, 1 Jan 2025
│
├── output/
│   ├── figure1.pdf
│   ├── figure1.png
│   ├── Final_Scrapped_Data_Purnima.csv   # Cleaned PM2.5 output
│   └── tables/
│       ├── tableA1_Annual_household_expenditure_MWK.csv
│       ├── tableA1.tex
│       ├── tableA2_charcoal.csv
│       ├── tableA2_charcoal.tex
│       ├── tableA2_electricity.csv
│       ├── tableA2_electricity.tex
│       ├── tableA2_firewood.csv
│       ├── tableA2_firewood.tex
│       ├── tableA7_Measures_of_womens_decision_making_DHS_2015_16.csv
│       └── tableA7.tex
│
└── README.md

How to run it

Set BASE_FOLDER

Open each R file and change one line at the top to match your computer:

# Mac/Linux:
BASE_FOLDER <- "/Users/yourname/Downloads/malawi-energy-replication"

# Windows:
# BASE_FOLDER <- "C:/Users/yourname/Downloads/malawi-energy-replication"

Then, place the raw data files in a Raw_Data/ folder inside that directory and run each script.

Install required packages

install.packages(c("haven", "dplyr", "xtable"))

Get the data

The raw data is not included in this repository. It comes from:

Run each script

Run the four R files in any order. Outputs save automatically to output/.


Packages used

library(haven)    # import Stata .dta files
library(dplyr)    # data cleaning and grouping
library(xtable)   # export LaTeX tables

A note on transparency

This was the first time I ran a full replication workflow in R. I documented every decision, every assumption, and every place where I could not exactly match the published output. Where numbers differed from the paper, I stated the reason explicitly rather than adjusting the code to force a match.

I think that is the right approach to replication work.


Data sources

  • Malawi Integrated Household Panel Survey (IHPS) 2010-2019
  • DHS 2015-16 Malawi
  • India CPCB Air Quality Data (10 cities, manually collected)

Part of my research portfolio: github.com/purnimaporwal

Author: Purnima Porwal | porwal.purnima18@gmail.com

About

Full replication of published Malawi energy paper in R, plus PM2.5 air quality data scrapping for India: Cooking fuel, household expenditure, energy prices, women's decision-making.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors