Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Food security indicators #180

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8591498
Updated comments
nicolefindstar Jul 25, 2024
1976788
Comment out read data
nicolefindstar Jul 29, 2024
2ff7701
Update FCSN
nicolefindstar Jul 29, 2024
da8dac8
FCS minor format
nicolefindstar Jul 29, 2024
bf9c18f
Upload FCS Source Scripts in Stata, R and Python
nicolefindstar Jul 29, 2024
153bd33
Updated rCSI labels, added Python version
nicolefindstar Jul 29, 2024
8a1cad7
Update MDDW and added python version
nicolefindstar Jul 29, 2024
3d97f99
Added HDDS Stata, R ans Python version
nicolefindstar Jul 29, 2024
59607c5
Minor edits to HDDS
nicolefindstar Jul 29, 2024
8688726
Updated HHS, added Stata R and Python versions
nicolefindstar Jul 29, 2024
57410a9
Updated Python version for ECMEN
nicolefindstar Jul 29, 2024
ee5e2e1
Minor edits to ECMEN
nicolefindstar Jul 29, 2024
ad88e3f
Updated FES, added R and Python versions
nicolefindstar Jul 30, 2024
3479dd7
Updated LCS-EN, formatted SPSS, added Stata, R and Ptyhon
nicolefindstar Jul 30, 2024
beba86d
Updated LCS-FS, formatted SPSS, added Stata, R and Ptyhon
nicolefindstar Jul 30, 2024
07162ec
Updated CARI-ECMEN, formatted SPSS and Stata, added R and Python
nicolefindstar Jul 30, 2024
fee3f97
Updated CARI-FES, formatted SPSS and Stata, added R and Python
nicolefindstar Jul 30, 2024
6dd4ba8
Updated ENA classification, formatted SPSS and Stata, added R and Python
nicolefindstar Jul 31, 2024
f4a440c
Updated Perceived Needs, formatted SPSS and Stata, added R and Python
nicolefindstar Aug 1, 2024
2e52412
Updated MDDI, formatted SPSS and Stata, added R and Python
nicolefindstar Aug 1, 2024
c74c90f
Updated MAD, formatted SPSS and R, added Stata and Python
nicolefindstar Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#------------------------------------------------------------------------------#
# WFP Standardized Scripts
# Consolidated Approach for Reporting Indicators of Food Security (CARI)
# CALCULATE CARI using FCS, rCSI, LCS and ECMEN
#------------------------------------------------------------------------------#

# Note that there are two ways to calculate CARI - using ECMEN or FES. This syntax
# file is for calculating CARI using ECMEN (version excluding assistance). However,
# please navigate to the script for CARI using FES as relevant.
# Guidance on CARI can be found here:
# https://www.wfp.org/publications/consolidated-approach-reporting-indicators-food-security-cari-guidelines.

# Note: this syntax file is based on the assumption that the scripts of the various
# indicators that compose this version of the CARI (FCS, rCSI, LCS-FS, ECMEN) have
# already been run. You can find these scripts here:
# https://github.com/WFP-VAM/RAMResourcesScripts/tree/main/Indicators.
# The following variables should have been defined before running this file:
# FCSCat21 and/or FCSCat28
# rCSI
# Max_coping_behaviourFS
# ECMEN_exclAsst
# ECMEN_exclAsst_SMEB.

library(tidyverse)
library(labelled)
library(expss)

# Load data
data <- read_csv("~/GitHub/RAMResourcesScripts/Static/CARI_FS_Sample_Survey.csv")

# Assign variable and value labels
var_label(data$FCSCat21) <- "FCS Categories (21/35 thresholds)"
var_label(data$rCSI) <- "Reduced Coping Strategies Index"
var_label(data$Max_coping_behaviourFS) <- "Max Coping Behaviour (FS)"
var_label(data$ECMEN_exclAsst) <- "Expenditure Capacity Measure Excluding Assistance"
var_label(data$ECMEN_exclAsst_SMEB) <- "Expenditure Capacity Measure Excluding Assistance (SMEB)"

# Process FCS for CARI computation
data <- data %>%
mutate(FCS_4pt = recode(FCSCat21, `1` = 4, `2` = 3, `3` = 1),
FCS_4pt = ifelse(rCSI >= 4 & FCS_4pt == 1, 2, FCS_4pt))

val_lab(data$FCS_4pt) <- num_lab("
1 Acceptable
2 Acceptable and rCSI>4
3 Borderline
4 Poor
")

# Process ECMEN for CARI computation
data <- data %>%
mutate(ECMEN_MEB = case_when(
ECMEN_exclAsst == 1 ~ 1,
ECMEN_exclAsst == 0 & ECMEN_exclAsst_SMEB == 1 ~ 2,
ECMEN_exclAsst == 0 & ECMEN_exclAsst_SMEB == 0 ~ 3
),
ECMEN_class_4pt = recode(ECMEN_MEB, `1` = 1, `2` = 3, `3` = 4))

val_lab(data$ECMEN_class_4pt) <- num_lab("
1 Least vulnerable
3 Vulnerable
4 Highly vulnerable
")

# Computation of CARI
data <- data %>%
mutate(Mean_coping_capacity_ECMEN = rowMeans(select(., Max_coping_behaviourFS, ECMEN_class_4pt), na.rm = TRUE),
CARI_unrounded_ECMEN = rowMeans(select(., FCS_4pt, Mean_coping_capacity_ECMEN), na.rm = TRUE),
CARI_ECMEN = round(CARI_unrounded_ECMEN))

var_label(data$CARI_ECMEN) <- "CARI classification (using ECMEN)"
val_lab(data$CARI_ECMEN) <- num_lab("
1 Food secure
2 Marginally food secure
3 Moderately food insecure
4 Severely food insecure
")

# Frequencies of CARI_ECMEN
cari_ecmen_freq <- data %>%
count(CARI_ECMEN) %>%
mutate(percentage = n / sum(n) * 100)
print(cari_ecmen_freq)

# Create population distribution table
pop_distribution_table <- data %>%
group_by(ECMEN_class_4pt, FCS_4pt, Max_coping_behaviourFS) %>%
summarise(count = n()) %>%
mutate(percentage = count / sum(count) * 100)
print(pop_distribution_table)

# Drop variables that are not needed
data <- data %>%
select(-ECMEN_MEB, -Mean_coping_capacity_ECMEN, -CARI_unrounded_ECMEN)

# End of Scripts
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
*** ----------------------------------------------------------------------------------------------------------------*

*** WFP Standard Scripts
*** Consolidated Approach for Reporting Indicators of Food Security (CARI)
*** CALCULATE CARI using FCS, rCSI, LCS and ECMEN

*** ----------------------------------------------------------------------------------------------------------------*
/*
Note that there are two ways to calculate CARI - using ECMEN or FES. This syntax file is for calculating CARI using ECMEN (version excluding assistance). However, please navigate to the script for CARI using FES as relevant.
Guidance on CARI can be found here: https://www.wfp.org/publications/consolidated-approach-reporting-indicators-food-security-cari-guidelines.

Note: this syntax file is based on the assumption that the scripts of the various indicators that compose this version of the CARI (FCS, rCSI, LCS-FS, ECMEN) have already been run.
You can find these scripts here: https://github.com/WFP-VAM/RAMResourcesScripts/tree/main/Indicators.
The following variables should have been defined before running this file:
FCSCat21 and/or FCSCat28
rCSI
Max_coping_behaviourFS
ECMEN_exclAsst
ECMEN_exclAsst_SMEB.
*/


*-------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
* WFP Standardized Scripts
* Consolidated Approach for Reporting Indicators of Food Security (CARI)
* CALCULATE CARI using FCS, rCSI, LCS and ECMEN
*------------------------------------------------------------------------------*

* Note that there are two ways to calculate CARI - using ECMEN or FES. This syntax
* file is for calculating CARI using ECMEN (version excluding assistance). However,
* please navigate to the script for CARI using FES as relevant.
* Guidance on CARI can be found here:
* https://www.wfp.org/publications/consolidated-approach-reporting-indicators-food-security-cari-guidelines.

* Note: this syntax file is based on the assumption that the scripts of the various
* indicators that compose this version of the CARI (FCS, rCSI, LCS-FS, ECMEN) have
* already been run. You can find these scripts here:
* https://github.com/WFP-VAM/RAMResourcesScripts/tree/main/Indicators.
* The following variables should have been defined before running this file:
* FCSCat21 and/or FCSCat28
* rCSI
* Max_coping_behaviourFS
* ECMEN_exclAsst
* ECMEN_exclAsst_SMEB.

*------------------------------------------------------------------------------*
* Process FCS for CARI computation
*-------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

* Create FCS_4pt for CARI calculation.
recode FCSCat21 (1=4) (2=3) (3=1), generate(FCS_4pt)
label variable FCS_4pt "4pt FCG"
label define FCS_4pt 1 "Acceptable" 3 "Borderline" 4 "Poor"
label values FCS_4pt FCS_4pt

*-------------------------------------------------------------------------------*
* Combine rCSI with FCS_4pt for CARI calculation (current consumption)
*-------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
* Combine rCSI with FCS_4pt for CARI calculation (current consumption)
*------------------------------------------------------------------------------*

recode FCS_4pt (1=2) if rCSI >= 4
label define FCS_4pt_lbl 1 "Acceptable" 2 "Acceptable and rCSI>4" 3 "Borderline" 4 "Poor"
label values FCS_4pt FCS_4pt_lbl

*-------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
* Process ECMEN for CARI computation
*-------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

* Recode ECMEN.
gen ECMEN_MEB = .
Expand All @@ -54,9 +55,9 @@ label variable ECMEN_class_4pt "ECMEN 4pt"
label define ECMEN_class_4pt_lbl 1 "Least vulnerable" 3 "Vulnerable" 4 "Highly vulnerable"
label values ECMEN_class_4pt ECMEN_class_4pt_lbl

*-------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
* Computation of CARI
*-------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

egen Mean_coping_capacity_ECMEN = rowmean(Max_coping_behaviourFS ECMEN_class_4pt)
egen CARI_unrounded_ECMEN = rowmean(FCS_4pt Mean_coping_capacity_ECMEN)
Expand All @@ -67,11 +68,14 @@ label values CARI_ECMEN CARI_ECMEN_lbl

tabulate CARI_ECMEN

* Create population distribution table, to explore how the domains interact within the different food security categories
table ( ECMEN_class_4pt) (FCS_4pt Max_coping_behaviourFS ), statistic(percent, across(Max_coping_behaviourFS)) nototal
* Create population distribution table to explore how the domains interact within
* the different food security categories.
table (ECMEN_class_4pt) (FCS_4pt Max_coping_behaviourFS), statistic(percent, across(Max_coping_behaviourFS)) nototal

*-------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
* Drop variables that are not needed
*-------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

drop ECMEN_MEB Mean_coping_capacity_ECMEN CARI_unrounded_ECMEN

* End of Scripts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#------------------------------------------------------------------------------#
# WFP Standardized Scripts
# Consolidated Approach for Reporting Indicators of Food Security (CARI)
# CALCULATE CARI using FCS, rCSI, LCS and ECMEN
#------------------------------------------------------------------------------#

# Note that there are two ways to calculate CARI - using ECMEN or FES. This syntax
# file is for calculating CARI using ECMEN (version excluding assistance). However,
# please navigate to the script for CARI using FES as relevant.
# Guidance on CARI can be found here:
# https://www.wfp.org/publications/consolidated-approach-reporting-indicators-food-security-cari-guidelines.

# Note: this syntax file is based on the assumption that the scripts of the various
# indicators that compose this version of the CARI (FCS, rCSI, LCS-FS, ECMEN) have
# already been run. You can find these scripts here:
# https://github.com/WFP-VAM/RAMResourcesScripts/tree/main/Indicators.
# The following variables should have been defined before running this file:
# FCSCat21 and/or FCSCat28
# rCSI
# Max_coping_behaviourFS
# ECMEN_exclAsst
# ECMEN_exclAsst_SMEB.

import pandas as pd
import numpy as np

# Load data
data = pd.read_csv("~/GitHub/RAMResourcesScripts/Static/CARI_FS_Sample_Survey.csv")

# Process FCS for CARI computation
data['FCS_4pt'] = data['FCSCat21'].replace({1: 4, 2: 3, 3: 1})
data.loc[data['rCSI'] >= 4, 'FCS_4pt'] = 2

# Process ECMEN for CARI computation
data['ECMEN_MEB'] = np.where(data['ECMEN_exclAsst'] == 1, 1,
np.where((data['ECMEN_exclAsst'] == 0) & (data['ECMEN_exclAsst_SMEB'] == 1), 2,
np.where((data['ECMEN_exclAsst'] == 0) & (data['ECMEN_exclAsst_SMEB'] == 0), 3, np.nan)))

data['ECMEN_class_4pt'] = data['ECMEN_MEB'].replace({1: 1, 2: 3, 3: 4})

# Computation of CARI
data['Mean_coping_capacity_ECMEN'] = data[['Max_coping_behaviourFS', 'ECMEN_class_4pt']].mean(axis=1, skipna=True)
data['CARI_unrounded_ECMEN'] = data[['FCS_4pt', 'Mean_coping_capacity_ECMEN']].mean(axis=1, skipna=True)
data['CARI_ECMEN'] = data['CARI_unrounded_ECMEN'].round().astype(int)

# Label mappings
fcs_4pt_labels = {1: "Acceptable", 2: "Acceptable and rCSI>4", 3: "Borderline", 4: "Poor"}
ecmen_class_4pt_labels = {1: "Least vulnerable", 3: "Vulnerable", 4: "Highly vulnerable"}
cari_ecmen_labels = {1: "Food secure", 2: "Marginally food secure", 3: "Moderately food insecure", 4: "Severely food insecure"}

data['FCS_4pt'] = data['FCS_4pt'].map(fcs_4pt_labels)
data['ECMEN_class_4pt'] = data['ECMEN_class_4pt'].map(ecmen_class_4pt_labels)
data['CARI_ECMEN'] = data['CARI_ECMEN'].map(cari_ecmen_labels)

# Frequencies of CARI_ECMEN
cari_ecmen_freq = data['CARI_ECMEN'].value_counts(normalize=True).reset_index()
cari_ecmen_freq.columns = ['CARI_ECMEN', 'percentage']
cari_ecmen_freq['percentage'] *= 100
print(cari_ecmen_freq)

# Create population distribution table
pop_distribution_table = data.pivot_table(index=['ECMEN_class_4pt', 'FCS_4pt'], columns='Max_coping_behaviourFS', aggfunc='size', fill_value=0)
pop_distribution_table = pop_distribution_table.div(pop_distribution_table.sum(axis=1), axis=0) * 100
print(pop_distribution_table)

# Drop variables that are not needed
data.drop(columns=['ECMEN_MEB', 'Mean_coping_capacity_ECMEN', 'CARI_unrounded_ECMEN'], inplace=True)

# End of Scripts
Loading