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

Updated ABI CRF 25, formatted SPSS and R, added Stata and Python #174

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
53 changes: 53 additions & 0 deletions Indicators/ABI-CRF-25/abi25.do
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions Indicators/ABI-CRF-25/abi25.py
Original file line number Diff line number Diff line change
@@ -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
119 changes: 63 additions & 56 deletions Indicators/ABI-CRF-25/abi25.sps
Original file line number Diff line number Diff line change
@@ -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
Loading