From 355f53a74b0ca82a42c3fc909acb77bf16251165 Mon Sep 17 00:00:00 2001 From: nicolefindstar Date: Tue, 30 Jul 2024 12:15:50 +0200 Subject: [PATCH] Updated ABI CRF 25, formatted SPSS and R, added Stata and Python --- Indicators/ABI-CRF-25/abi25.do | 53 +++++++++++ Indicators/ABI-CRF-25/abi25.py | 57 ++++++++++++ Indicators/ABI-CRF-25/abi25.sps | 119 +++++++++++++----------- Indicators/ABI-CRF-25/abi25_tidyverse.R | 87 +++++++++-------- 4 files changed, 221 insertions(+), 95 deletions(-) create mode 100644 Indicators/ABI-CRF-25/abi25.do create mode 100644 Indicators/ABI-CRF-25/abi25.py diff --git a/Indicators/ABI-CRF-25/abi25.do b/Indicators/ABI-CRF-25/abi25.do new file mode 100644 index 0000000..ce6839e --- /dev/null +++ b/Indicators/ABI-CRF-25/abi25.do @@ -0,0 +1,53 @@ +*------------------------------------------------------------------------------* +* WFP Standardized Scripts +* Calculating Asset-Based Indicator (ABI) 25 +*------------------------------------------------------------------------------* + +* This script calculates the Asset-Based Indicator (ABI) based on various +* asset-related questions. It recodes the responses, sums the scores, and +* calculates the percentage ABI for each respondent. + +* Label ABI relevant variables +label var HHFFAPart "Have you or any of your household member participated in the asset creation activities and received a food assistance transfer?" +label var HHAssetProtect "Do you think that the assets that were built or rehabilitated in your community are better protecting your household from floods / drought / landslides / mudslides?" +label var HHAssetProduct "Do you think that the assets that were built or rehabilitated in your community have allowed your household to increase or diversify its production (agriculture / livestock / other)?" +label var HHAssetDecHardship "Do you think that the assets that were built or rehabilitated in your community have decreased the day-to-day hardship and released time for any of your family members (including women and children)?" +label var HHAssetAccess "Do you think that the assets that were built or rehabilitated in your community have improved the ability of any of your household member to access markets and/or basic services (water, sanitation, health, education, etc)?" +label var HHTrainingAsset "Do you think that the trainings and other support provided in your community have improved your household’s ability to manage and maintain assets?" +label var HHAssetEnv "Do you think that the assets that were built or rehabilitated in your community have improved your natural environment (for example more vegetal cover, water table increased, less erosion, etc.)?" +label var HHWorkAsset "Do you think that the works undertaken in your community have restored your ability to access and/or use basic asset functionalities?" + +* Define value labels +label define HHFFAPart_lbl 0 "No" 1 "Yes" +label values HHFFAPart HHFFAPart_lbl + +label define ABI_lbl 0 "No" 1 "Yes" 9999 "Not applicable" +label values HHAssetProtect HHAssetProduct HHAssetDecHardship HHAssetAccess HHTrainingAsset HHAssetEnv HHWorkAsset ABI_lbl + +* Recode 9999 to 0 +foreach var of varlist HHAssetProtect HHAssetProduct HHAssetDecHardship HHAssetAccess HHTrainingAsset HHAssetEnv HHWorkAsset { + replace `var' = 0 if `var' == 9999 +} + +* Create denominator of questions asked for each community +gen ABIdenom = . +replace ABIdenom = 5 if ADMIN5Name == "Community A" +replace ABIdenom = 6 if ADMIN5Name == "Community B" + +* Create ABI score and ABI percent +gen ABIScore = HHAssetProtect + HHAssetProduct + HHAssetDecHardship + HHAssetAccess + HHTrainingAsset + HHAssetEnv + HHWorkAsset +gen ABIPerc = (ABIScore / ABIdenom) * 100 + +* Create table of values - participants vs non-participants +collapse (mean) ABIPerc, by(HHFFAPart) +rename ABIPerc ABIPerc_mean + +* Calculate ABI using weight value of 2 for non-participants +gen ABIperc_wtd = ABIPerc_mean +replace ABIperc_wtd = ABIPerc_mean * 2 if HHFFAPart == 0 + +* Add weight for non-participant and compute average +gen ABIperc_total_partic = ABIperc_wtd / 3 +collapse (sum) ABIperc_total_partic + +* End of Scripts \ No newline at end of file diff --git a/Indicators/ABI-CRF-25/abi25.py b/Indicators/ABI-CRF-25/abi25.py new file mode 100644 index 0000000..2e5135b --- /dev/null +++ b/Indicators/ABI-CRF-25/abi25.py @@ -0,0 +1,57 @@ +#------------------------------------------------------------------------------# +# WFP Standardized Scripts +# Calculating Asset-Based Indicator (ABI) 25 +#------------------------------------------------------------------------------# + +# This script calculates the Asset-Based Indicator (ABI) based on various +# asset-related questions. It recodes the responses, sums the scores, and +# calculates the percentage ABI for each respondent. + +# Load Packages +import pandas as pd + +# Import dataset +#data = pd.read_csv("~/GitHub/RAMResourcesScripts/Static/ABI_Sample_Survey.csv") + +# Assign variable and value labels +data = data.rename(columns={ + 'HHFFAPart': 'Have you or any of your household member participated in the asset creation activities and received a food assistance transfer?', + 'HHAssetProtect': 'Do you think that the assets that were built or rehabilitated in your community are better protecting your household from floods / drought / landslides / mudslides?', + 'HHAssetProduct': 'Do you think that the assets that were built or rehabilitated in your community have allowed your household to increase or diversify its production (agriculture / livestock / other)?', + 'HHAssetDecHardship': 'Do you think that the assets that were built or rehabilitated in your community have decreased the day-to-day hardship and released time for any of your family members (including women and children)?', + 'HHAssetAccess': 'Do you think that the assets that were built or rehabilitated in your community have improved the ability of any of your household member to access markets and/or basic services (water, sanitation, health, education, etc)?', + 'HHTrainingAsset': 'Do you think that the trainings and other support provided in your community have improved your household’s ability to manage and maintain assets?', + 'HHAssetEnv': 'Do you think that the assets that were built or rehabilitated in your community have improved your natural environment (for example more vegetal cover, water table increased, less erosion, etc.)?', + 'HHWorkAsset': 'Do you think that the works undertaken in your community have restored your ability to access and/or use basic asset functionalities?' +}) + +# Define value labels +value_labels = { + 0: "No", + 1: "Yes", + 9999: "Not applicable" +} +for column in ['HHAssetProtect', 'HHAssetProduct', 'HHAssetDecHardship', 'HHAssetAccess', 'HHTrainingAsset', 'HHAssetEnv', 'HHWorkAsset']: + data[column] = data[column].map(value_labels) + +# Recode 9999 to 0 +for column in ['HHAssetProtect', 'HHAssetProduct', 'HHAssetDecHardship', 'HHAssetAccess', 'HHTrainingAsset', 'HHAssetEnv', 'HHWorkAsset']: + data[column] = data[column].replace(9999, 0) + +# Create denominator of questions asked for each community +data['ABIdenom'] = data['ADMIN5Name'].apply(lambda x: 5 if x == 'Community A' else 6) + +# Create ABI score and ABI percent +data['ABIScore'] = data[['HHAssetProtect', 'HHAssetProduct', 'HHAssetDecHardship', 'HHAssetAccess', 'HHTrainingAsset', 'HHAssetEnv', 'HHWorkAsset']].sum(axis=1) +data['ABIPerc'] = (data['ABIScore'] / data['ABIdenom']) * 100 + +# Create table of values - participants vs non-participants +ABIperc_particp = data.groupby('HHFFAPart')['ABIPerc'].mean().reset_index(name='ABIPerc_mean') + +# Calculate ABI using weight value of 2 for non-participants +ABIperc_particp['ABIperc_wtd'] = ABIperc_particp.apply(lambda x: x['ABIPerc_mean'] * 2 if x['HHFFAPart'] == 0 else x['ABIPerc_mean'], axis=1) + +# Add weight for non-participant and compute average +ABIperc_total = ABIperc_particp['ABIperc_wtd'].sum() / 3 + +# End of Scripts \ No newline at end of file diff --git a/Indicators/ABI-CRF-25/abi25.sps b/Indicators/ABI-CRF-25/abi25.sps index 82b3309..c0216f3 100644 --- a/Indicators/ABI-CRF-25/abi25.sps +++ b/Indicators/ABI-CRF-25/abi25.sps @@ -1,73 +1,80 @@ -* Encoding: UTF-8. - -* define variable and value labels - -Variable labels HHFFAPart "Have you or any of your household member participated in the asset creation activities and received a food assistance transfer?". - Variable labels HHAssetProtect "Do you think that the assets that were built or rehabilitated in your community are better protecting your household, from floods / drought / landslides / mudslides?". - Variable labels HHAssetProduct "Do you think that the assets that were built or rehabilitated in your community have allowed your household to increase or diversify its production (agriculture / livestock / other)?". - Variable labels HHAssetDecHardship "Do you think that the assets that were built or rehabilitated in your community have decreased the day-to-day hardship and released time for any of your family members (including women and children)?". - Variable labels HHAssetAccess "Do you think that the assets that were built or rehabilitated in your community have improved the ability of any of your household member to access markets and/or basic services (water, sanitation, health, education, etc)?". - Variable labels HHTrainingAsset "Do you think that the trainings and other support provided in your community have improved your household’s ability to manage and maintain assets?". - Variable labels HHAssetEnv "Do you think that the assets that were built or rehabilitated in your community have improved your natural environment (for example more vegetal cover, water table increased, less erosion, etc.)?". - Variable labels HHWorkAsset "Do you think that the works undertaken in your community have restored your ability to access and/or use basic asset functionalities?". - - Value labels HHFFAPart 1 'Yes' 0 'No'. -Value labels HHAssetProtect HHAssetProduct HHAssetDecHardship HHAssetAccess HHTrainingAsset HHAssetEnv HHWorkAsset 1 'Yes' 0 'No' 9999 "Not applicable". - -*take a look at of responses by community and note how many questions (and which were not answered by each community) for each community - -CROSSTABS - /TABLES= HHAssetProtect HHAssetProduct HHAssetDecHardship HHAssetAccess HHTrainingAsset HHAssetEnv HHWorkAsset BY ADMIN5Name - /CELLS=COUNT - /COUNT ROUND CELL. - -* recode 9999 to 0 - -RECODE HHAssetProtect HHAssetProduct HHAssetDecHardship HHAssetAccess HHTrainingAsset HHAssetEnv HHWorkAsset (9999=0) (0=0) (1=1). +*------------------------------------------------------------------------------* +* WFP Standardized Scripts +* Calculating Asset-Based Indicator (ABI) 25 +*------------------------------------------------------------------------------* + +* This script calculates the Asset-Based Indicator (ABI) based on various +* asset-related questions. It recodes the responses, sums the scores, and +* calculates the percentage ABI for each respondent. + +* Define variable and value labels +Variable labels + HHFFAPart "Have you or any of your household member participated in the asset creation activities and received a food assistance transfer?". + HHAssetProtect "Do you think that the assets that were built or rehabilitated in your community are better protecting your household from floods / drought / landslides / mudslides?". + HHAssetProduct "Do you think that the assets that were built or rehabilitated in your community have allowed your household to increase or diversify its production (agriculture / livestock / other)?". + HHAssetDecHardship "Do you think that the assets that were built or rehabilitated in your community have decreased the day-to-day hardship and released time for any of your family members (including women and children)?". + HHAssetAccess "Do you think that the assets that were built or rehabilitated in your community have improved the ability of any of your household member to access markets and/or basic services (water, sanitation, health, education, etc)?". + HHTrainingAsset "Do you think that the trainings and other support provided in your community have improved your household’s ability to manage and maintain assets?". + HHAssetEnv "Do you think that the assets that were built or rehabilitated in your community have improved your natural environment (for example more vegetal cover, water table increased, less erosion, etc.)?". + HHWorkAsset "Do you think that the works undertaken in your community have restored your ability to access and/or use basic asset functionalities?". + +Value labels + HHFFAPart 1 'Yes' 0 'No'. + HHAssetProtect + HHAssetProduct + HHAssetDecHardship + HHAssetAccess + HHTrainingAsset + HHAssetEnv + HHWorkAsset 1 'Yes' 0 'No' 9999 "Not applicable". + +* Recode 9999 to 0 +RECODE + HHAssetProtect + HHAssetProduct + HHAssetDecHardship + HHAssetAccess + HHTrainingAsset + HHAssetEnv + HHWorkAsset (9999 = 0) (0 = 0) (1 = 1). EXECUTE. - -*create values with the denominator of questions asked for each community - should scan through the data and values from tables above to generate these values - -do if ADMIN5Name = "Community A". -compute ABIdenom =5. -else. -compute ABIdenom = 6. -end if. +* Create denominator of questions asked for each community +DO IF ADMIN5Name = "Community A". + COMPUTE ABIdenom = 5. +ELSE. + COMPUTE ABIdenom = 6. +END IF. EXECUTE. -*Create ABI score (summing all response) and ABI percent (dividing total score by denominator of applicaple questions) - -Compute ABIScore = sum(HHAssetProtect,HHAssetProduct,HHAssetDecHardship,HHAssetAccess,HHTrainingAsset,HHAssetEnv,HHWorkAsset). -Compute ABIPerc = ((ABIScore / ABIdenom) * 100). +* Create ABI score and ABI percent +COMPUTE ABIScore = SUM(HHAssetProtect, HHAssetProduct, HHAssetDecHardship, HHAssetAccess, HHTrainingAsset, HHAssetEnv, HHWorkAsset). +COMPUTE ABIPerc = ((ABIScore / ABIdenom) * 100). EXECUTE. - -* Creates table of values - participants vs non-participants - +* Create table of values - participants vs non-participants DATASET DECLARE ABIperc_particp. AGGREGATE /OUTFILE='ABIperc_particp' /BREAK=HHFFAPart - /ABIPerc_mean=MEAN(ABIPerc). - -* calculate the ABI across using weight value of 2 for non-participants which accounts for sampling imbalance between participants and non-participants -* if ration of participants vs non-participants is not 2/1 then a more sophisticated method for creating weights should be used - -Dataset Activate ABIperc_particp. -do if HHFFAPart = 0. -compute ABIperc_wtd =2. -else. -compute ABIperc_wtd = 1. -end if. + /ABIPerc_mean = MEAN(ABIPerc). + +* Calculate ABI using weight value of 2 for non-participants +DATASET ACTIVATE ABIperc_particp. +DO IF HHFFAPart = 0. + COMPUTE ABIperc_wtd = 2. +ELSE. + COMPUTE ABIperc_wtd = 1. +END IF. EXECUTE. -* add weight for non particpant and compute average - -compute ABIperc_total_partic = ((ABIPerc_mean * ABIperc_wtd)/3). +* Add weight for non-participant and compute average +COMPUTE ABIperc_total_partic = ((ABIPerc_mean * ABIperc_wtd) / 3). EXECUTE. AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK= - /ABIperc_total =SUM(ABIperc_total_partic). + /ABIperc_total = SUM(ABIperc_total_partic). + +* End of Scripts \ No newline at end of file diff --git a/Indicators/ABI-CRF-25/abi25_tidyverse.R b/Indicators/ABI-CRF-25/abi25_tidyverse.R index a5e1362..431a703 100644 --- a/Indicators/ABI-CRF-25/abi25_tidyverse.R +++ b/Indicators/ABI-CRF-25/abi25_tidyverse.R @@ -1,61 +1,70 @@ +#------------------------------------------------------------------------------# +# WFP Standardized Scripts +# Calculating Asset-Based Indicator (ABI) 25 +#------------------------------------------------------------------------------# + +# This script calculates the Asset-Based Indicator (ABI) based on various +# asset-related questions. It recodes the responses, sums the scores, and +# calculates the percentage ABI for each respondent. + +# Load Packages library(tidyverse) library(labelled) library(expss) -#import dataset -data <- read_csv("~/GitHub/RAMResourcesScripts/Static/ABI_Sample_Survey.csv") +# Import dataset +#data <- read_csv("~/GitHub/RAMResourcesScripts/Static/ABI_Sample_Survey.csv") -#assign variable and value labels -var_label(data$HHFFAPart) <- "Have you or any of your household member participated in the asset creation activities and received a food assistance transfer?" -var_label(data$HHAssetProtect) <- "Do you think that the assets that were built or rehabilitated in your community are better protecting your household, its belongings and its production capacities (fields, equipment, etc.) from floods / drought / landslides / mudslides?" -var_label(data$HHAssetProduct) <- "Do you think that the assets that were built or rehabilitated in your community have allowed your household to increase or diversify its production (agriculture / livestock / other)?" +# Assign variable and value labels +var_label(data$HHFFAPart) <- "Have you or any of your household member participated in the asset creation activities and received a food assistance transfer?" +var_label(data$HHAssetProtect) <- "Do you think that the assets that were built or rehabilitated in your community are better protecting your household, its belongings and its production capacities (fields, equipment, etc.) from floods / drought / landslides / mudslides?" +var_label(data$HHAssetProduct) <- "Do you think that the assets that were built or rehabilitated in your community have allowed your household to increase or diversify its production (agriculture / livestock / other)?" var_label(data$HHAssetDecHardship) <- "Do you think that the assets that were built or rehabilitated in your community have decreased the day-to-day hardship and released time for any of your family members (including women and children)?" -var_label(data$HHAssetAccess) <- "Do you think that the assets that were built or rehabilitated in your community have improved the ability of any of your household member to access markets and/or basic services (water, sanitation, health, education, etc)?" -var_label(data$HHTrainingAsset) <- "Do you think that the trainings and other support provided in your community have improved your household’s ability to manage and maintain assets?" -var_label(data$HHAssetEnv) <- "Do you think that the assets that were built or rehabilitated in your community have improved your natural environment (for example more vegetal cover, water table increased, less erosion, etc.)?" -var_label(data$HHWorkAsset) <- "Do you think that the works undertaken in your community have restored your ability to access and/or use basic asset functionalities?" +var_label(data$HHAssetAccess) <- "Do you think that the assets that were built or rehabilitated in your community have improved the ability of any of your household member to access markets and/or basic services (water, sanitation, health, education, etc)?" +var_label(data$HHTrainingAsset) <- "Do you think that the trainings and other support provided in your community have improved your household’s ability to manage and maintain assets?" +var_label(data$HHAssetEnv) <- "Do you think that the assets that were built or rehabilitated in your community have improved your natural environment (for example more vegetal cover, water table increased, less erosion, etc.)?" +var_label(data$HHWorkAsset) <- "Do you think that the works undertaken in your community have restored your ability to access and/or use basic asset functionalities?" data <- data %>% - mutate(across(c(HHAssetProtect,HHAssetProduct,HHAssetDecHardship,HHAssetAccess,HHTrainingAsset,HHAssetEnv,HHWorkAsset), ~labelled(., labels = c( - "No" = 0, - "Yes" = 1, - "Not applicable" = 9999 - )))) - -val_lab(data$HHFFAPart) = num_lab(" - 0 No - 1 Yes -") - -#recode 999 to 0 + mutate(across(c(HHAssetProtect, HHAssetProduct, HHAssetDecHardship, HHAssetAccess, HHTrainingAsset, HHAssetEnv, HHWorkAsset), + ~labelled(., labels = c("No" = 0, "Yes" = 1, "Not applicable" = 9999)))) + +val_lab(data$HHFFAPart) = num_lab("0 No + 1 Yes") + +# Recode 9999 to 0 data <- data %>% mutate(across(HHAssetProtect:HHWorkAsset, ~ dplyr::recode(.x, "0" = 0, "1" = 1, "9999" = 0))) - -#sum ABI rows +# Sum ABI rows data <- data %>% mutate(ABIScore = rowSums(across(c(HHAssetProtect:HHWorkAsset)))) -#create denominator of questions asked +# Create denominator of questions asked data <- data %>% mutate(ABIdenom = case_when( ADMIN5Name == "Community A" ~ 5, ADMIN5Name == "Community B" ~ 6 )) -#create % ABI for each respondent -data <- data %>% mutate(ABIperc = round((ABIScore/ABIdenom)*100)) +# Create % ABI for each respondent +data <- data %>% mutate(ABIperc = round((ABIScore / ABIdenom) * 100)) + +# Create table comparing ABI % of participants and non-participants by village +ABIperc_particp_ADMIN5Name <- data %>% + mutate(HHFFAPart_lab = to_character(HHFFAPart)) %>% + group_by(ADMIN5Name, HHFFAPart_lab) %>% + summarize(ABIperc = mean(ABIperc)) -#create table comparing ABI % of participants and non-participants by village -ABIperc_particp_ADMIN5Name <- data %>% mutate(HHFFAPart_lab = to_character(HHFFAPart)) %>% group_by(ADMIN5Name, HHFFAPart_lab) %>% summarize(ABIperc = mean(ABIperc)) +# Create table presenting ABI % participants vs non-participants (average across villages) +ABIperc_particp <- data %>% + mutate(HHFFAPart_lab = to_character(HHFFAPart)) %>% + group_by(HHFFAPart_lab) %>% + summarize(ABIperc = mean(ABIperc)) -#create table presenting ABI % participants vs non-particpants (average across villages) -ABIperc_particp <- data %>% mutate(HHFFAPart_lab = to_character(HHFFAPart)) %>% group_by(HHFFAPart_lab) %>% summarize(ABIperc = mean(ABIperc)) +# Calculate the ABI across using weight value of 2 for non-participants which accounts for sampling imbalance +ABIperc_total <- ABIperc_particp %>% + mutate(ABIperc_wtd = case_when(HHFFAPart_lab == "No" ~ ABIperc * 2, TRUE ~ ABIperc)) %>% + ungroup() %>% + summarize(ABIperc_total = sum(ABIperc_wtd) / 3) -#calculate the ABI across using weight value of 2 for non-participants which accounts for sampling imbalance between nonparticipants and participants -#if ratio of participants/vs non-participants is not 2/1 then a more sophisticated method for creating weights should be used. -ABIperc_total <- ABIperc_particp %>% mutate(ABIperc_wtd = case_when(HHFFAPart_lab == "No" ~ ABIperc *2, TRUE ~ ABIperc)) %>% ungroup() %>% summarize(ABIperc_total = sum(ABIperc_wtd)/3) - - - - - \ No newline at end of file +# End of Scripts \ No newline at end of file