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

Indicator nutrition #176

Open
wants to merge 2 commits 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
23 changes: 23 additions & 0 deletions Indicators/Nutrition-CRF-7-coverage/nut7_coverage.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
*------------------------------------------------------------------------------*
* WFP Standardized Scripts
* NUT7 Coverage Indicator
*------------------------------------------------------------------------------*

* Note: This syntax file processes the NUT7 coverage indicator by assessing
* participant enrollment in a specified nutrition program.

* Can only download repeat CSV data as a zip file from MODA with group names.
* Will update this code to remove group names.

* Rename to remove group names.
rename Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgPartic PNutProgPartic_yn

* Define variable and value labels.
label variable PNutProgPartic_yn "Is participant enrolled in the ((insert name/description of program, to be adapted locally)) programme?"
label define PNutProgPartic_yn_label 0 "No" 1 "Yes"
label values PNutProgPartic_yn PNutProgPartic_yn_label

* Frequency table for PNutProgPartic_yn.
tabulate PNutProgPartic_yn

* End of Scripts.
29 changes: 29 additions & 0 deletions Indicators/Nutrition-CRF-7-coverage/nut7_coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#------------------------------------------------------------------------------#
# WFP Standardized Scripts
# NUT7 Coverage Indicator
#------------------------------------------------------------------------------#

# Note: This script processes the NUT7 coverage indicator by assessing participant
# enrollment in a specified nutrition program.

import pandas as pd
import numpy as np

# Add sample data.
#data = pd.read_csv("~/GitHub/RAMResourcesScripts/Static/Nut_CRF_7_coverage_Sample_Survey/Nutrition_module_NutProg_submodule_RepeatNutProg.csv")

# Can only download repeat CSV data as a zip file from MODA with group names.
# Rename to remove group names.
data = data.rename(columns={'Nutrition_module/NutProg_submodule/RepeatNutProg/PNutProgPartic_yn': 'PNutProgPartic_yn'})

# Assign variable and value labels.
data['PNutProgPartic_yn'] = data['PNutProgPartic_yn'].astype('category')
data['PNutProgPartic_yn'].cat.categories = ["No", "Yes"]
data['PNutProgPartic_yn'].cat.set_categories([0, 1], rename=True, inplace=True)

# Create a table of the weighted percentage of NutProgPartic_yn.
nut_prog_partic_yn_table = data['PNutProgPartic_yn'].value_counts(normalize=True).reset_index()
nut_prog_partic_yn_table.columns = ['PNutProgPartic_yn', 'Percentage']
nut_prog_partic_yn_table['Percentage'] = nut_prog_partic_yn_table['Percentage'] * 100

# End of Scripts.
24 changes: 17 additions & 7 deletions Indicators/Nutrition-CRF-7-coverage/nut7_coverage.sps
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
* Encoding: UTF-8.
********************************************************************************
* WFP Standardized Scripts
* NUT7 Coverage Indicator
********************************************************************************

*can only download repeat csv data as zip file from moda with group names - will update this code to remove group names
*rename to remove group names - because of the variable length SPSS changes name slightly
* Note: This syntax file processes the NUT7 coverage indicator by assessing
* participant enrollment in a specified nutrition program.

* Define variable and value labels.

* Can only download repeat CSV data as a zip file from MODA with group names.
* Will update this code to remove group names.

RENAME VARIABLES (Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgPartic = PNutProgPartic_yn).

* define variable and value labels
* Define variable and value labels.

Variable labels PNutProgPartic_yn Is participant enrolled in the ((insert name/description of program, to be adapted locally)) programme?.
VARIABLE LABELS PNutProgPartic_yn 'Is participant enrolled in the ((insert name/description of program, to be adapted locally)) programme?'.

Value labels PNutProgPartic_ynNutProgPartic_yn 1 'Yes' 0 'No '.
VALUE LABELS PNutProgPartic_yn 1 'Yes' 0 'No'.

freq PNutProgPartic_yn.
* Frequency table for PNutProgPartic_yn.
FREQUENCIES VARIABLES=PNutProgPartic_yn.

* End of Scripts.
44 changes: 24 additions & 20 deletions Indicators/Nutrition-CRF-7-coverage/nut7_coverage_tidyverse.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
#------------------------------------------------------------------------------#
# WFP Standardized Scripts
# NUT7 Coverage Indicator
#------------------------------------------------------------------------------#

# Note: This script processes the NUT7 coverage indicator by assessing participant
# enrollment in a specified nutrition program.

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

#add sample data
data <- read_csv("~/GitHub/RAMResourcesScripts/Static/Nut_CRF_7_coverage_Sample_Survey/Nutrition_module_NutProg_submodule_RepeatNutProg.csv")
# Add sample data.
#data <- read_csv("~/GitHub/RAMResourcesScripts/Static/Nut_CRF_7_coverage_Sample_Survey/Nutrition_module_NutProg_submodule_RepeatNutProg.csv")

#can only download repeat csv data as zip file from moda with group names - will update this code to remove group names
#rename to remove group names
# Can only download repeat CSV data as a zip file from MODA with group names.
# Rename to remove group names.
data <- data %>% rename(PNutProgPartic_yn = 'Nutrition_module/NutProg_submodule/RepeatNutProg/PNutProgPartic_yn')


#assign variable and value labels
var_label(data$PNutProgPartic_yn) <- "Is participant enrolled in the ((insert name/description of program, to be adapted locally)) programme?"
# Assign variable and value labels.
var_label(data$PNutProgPartic_yn) <- "Is participant enrolled in the ((insert name/description of program, to be adapted locally)) programme?"
val_lab(data$PNutProgPartic_yn) = num_lab("
0 No
1 Yes
")


#creates a table of the weighted percentage of NutProgPartic_yn by
#creating a temporary variable to display value labels
#and providing the option to use weights if needed


NutProgPartic_yn_table_wide <- data %>%
# Create a table of the weighted percentage of NutProgPartic_yn.
NutProgPartic_yn_table_wide <- data %>%
drop_na(PNutProgPartic_yn) %>%
count(PNutProgPartic_yn_lab = as.character(PNutProgPartic_yn)) %>% # if weights are needed use instead the row below
#count(PNutProgPartic_yn_lab = as.character(PNutProgPartic_yn), wt = nameofweightvariable)
count(PNutProgPartic_yn_lab = as.character(PNutProgPartic_yn)) %>%
# Use the line below if weights are needed.
# count(PNutProgPartic_yn_lab = as.character(PNutProgPartic_yn), wt = nameofweightvariable)
mutate(Percentage = 100 * n / sum(n)) %>%
ungroup() %>% select(-n) %>%
pivot_wider(names_from = PNutProgPartic_yn_lab,
values_from = Percentage,
values_fill = 0)
ungroup() %>%
select(-n) %>%
pivot_wider(names_from = PNutProgPartic_yn_lab, values_from = Percentage, values_fill = 0)

# End of Scripts.
54 changes: 33 additions & 21 deletions Indicators/Nutrition-CRF-8-adherence/nut8_adherence.do
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
*add sample data
import delimited using "../../Static/Nut_CRF_8_adherence_Sample_Survey/Nutrition_module_NutProg_submodule_RepeatNutProg.csv"
*------------------------------------------------------------------------------*
* WFP Standardized Scripts
* NUT8 Adherence Indicator
*------------------------------------------------------------------------------*

* Note: This syntax file processes the NUT8 adherence indicator by assessing
* whether participants received an adequate number of distributions as per
* program requirements.

rename (v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13) (PNutProgParticName PNutProgCard PNutProgShouldNbrCard PNutProgDidNbrCard PNutwhendate PNutProgShouldNbrNoCard PNutProgDidNbrNoCard PNutProgEntitlements PNoNutProgReason PNoNutProgReason_other PNoNutProgCardReason PNoNutProgCardReason_other)
*#assign variable labels
* Can only download repeat CSV data as a zip file from MODA with group names.
* Will update this code to remove group names.

label var PNutProgCard "May I see participant's program participation card?"
label var PNutProgShouldNbrCard "number of distributions entitled to - measured with participation card"
label var PNutProgDidNbrCard "number of distributions received - measured with participation card"
label var PNutProgShouldNbrNoCard "number of distributions entitled to - measured without participation card"
label var PNutProgDidNbrNoCard "number of distributions received - measured without participation card"
label define Yesno 1 "Yes" 0 "No"

*#create variable which classifies if participant received 66% or more of planned distributions
gen NutProgRecAdequate=cond((PNutProgCard == 1 & ((PNutProgDidNbrCard / PNutProgShouldNbrCard) >= .66) == 1) | ///
(PNutProgCard == 0 & ((PNutProgDidNbrNoCard / PNutProgShouldNbrNoCard) >= .66) == 1),1,0)
label var NutProgRecAdequate "Participant recieved adequate number of distributions?"
* Add sample data.
*import delimited using "~/GitHub/RAMResourcesScripts/Static/Nut_CRF_8_adherence_Sample_Survey/Nutrition_module_NutProg_submodule_RepeatNutProg.csv"

* Rename to remove group names.
rename Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgCard PNutProgCard
rename Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgShouldN_A PNutProgShouldNbrCard
rename Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgDidNbrC PNutProgDidNbrCard
rename Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgShouldN PNutProgShouldNbrNoCard
rename Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgDidNbrN PNutProgDidNbrNoCard

* Define variable and value labels.
label variable PNutProgCard "May I see participant's program participation card?"
label variable PNutProgShouldNbrCard "Number of distributions entitled to - measured with participation card"
label variable PNutProgDidNbrCard "Number of distributions received - measured with participation card"
label variable PNutProgShouldNbrNoCard "Number of distributions entitled to - measured without participation card"
label variable PNutProgDidNbrNoCard "Number of distributions received - measured without participation card"
label define Yesno 1 "Yes" 0 "No"
label values PNutProgCard NutProgRecAdequate Yesno

/*
#creates a table of the weighted percentage of NutProgRecAdequate by
#creating a temporary variable to display value labels
#and providing the option to use weights if needed
*/
cap gen WeightHH=1
* Create variable which classifies if participant received 66% or more of planned distributions.
gen NutProgRecAdequate = cond((PNutProgCard == 1 & ((PNutProgDidNbrCard / PNutProgShouldNbrCard) >= .66)) | ///
(PNutProgCard == 0 & ((PNutProgDidNbrNoCard / PNutProgShouldNbrNoCard) >= .66)), 1, 0)
label variable NutProgRecAdequate "Participant received adequate number of distributions?"

* Create a table of the weighted percentage of NutProgRecAdequate.
cap gen WeightHH = 1
tabulate NutProgRecAdequate [aw=WeightHH]

* End of Scripts.
47 changes: 47 additions & 0 deletions Indicators/Nutrition-CRF-8-adherence/nut8_adherence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#------------------------------------------------------------------------------#
# WFP Standardized Scripts
# NUT8 Adherence Indicator
#------------------------------------------------------------------------------#

# Note: This script processes the NUT8 adherence indicator by assessing
# whether participants received an adequate number of distributions as per
# program requirements.

import pandas as pd
import numpy as np

# Add sample data
#data = pd.read_csv("~/GitHub/RAMResourcesScripts/Static/Nut_CRF_8_adherence_Sample_Survey/Nutrition_module_NutProg_submodule_RepeatNutProg.csv")

# Can only download repeat CSV data as a zip file from MODA with group names.
# Rename to remove group names.
data = data.rename(columns={
'Nutrition_module/NutProg_submodule/RepeatNutProg/PNutProgCard': 'PNutProgCard',
'Nutrition_module/NutProg_submodule/RepeatNutProg/PNutProgShouldNbrCard': 'PNutProgShouldNbrCard',
'Nutrition_module/NutProg_submodule/RepeatNutProg/PNutProgDidNbrCard': 'PNutProgDidNbrCard',
'Nutrition_module/NutProg_submodule/RepeatNutProg/PNutProgShouldNbrNoCard': 'PNutProgShouldNbrNoCard',
'Nutrition_module/NutProg_submodule/RepeatNutProg/PNutProgDidNbrNoCard': 'PNutProgDidNbrNoCard'
})

# Assign variable and value labels.
data['PNutProgCard'] = data['PNutProgCard'].astype('category')
data['PNutProgCard'].cat.rename_categories({0: 'No', 1: 'Yes'}, inplace=True)

# Create variable which classifies if participant received 66% or more of planned distributions.
data['NutProgRecAdequate'] = np.where(
(data['PNutProgCard'] == 'Yes') & ((data['PNutProgDidNbrCard'] / data['PNutProgShouldNbrCard']) >= 0.66) |
(data['PNutProgCard'] == 'No') & ((data['PNutProgDidNbrNoCard'] / data['PNutProgShouldNbrNoCard']) >= 0.66),
1, 0
)
data['NutProgRecAdequate'] = data['NutProgRecAdequate'].astype('category')
data['NutProgRecAdequate'].cat.rename_categories({0: 'No', 1: 'Yes'}, inplace=True)

# Create a table of the weighted percentage of NutProgRecAdequate.
nutprog_table = data['NutProgRecAdequate'].value_counts(normalize=True).reset_index()
nutprog_table.columns = ['NutProgRecAdequate', 'Percentage']
nutprog_table['Percentage'] *= 100

# Print the table.
print(nutprog_table)

# End of Scripts.
58 changes: 33 additions & 25 deletions Indicators/Nutrition-CRF-8-adherence/nut8_adherence.sps
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
* Encoding: UTF-8.
********************************************************************************
* WFP Standardized Scripts
* NUT8 Adherence Indicator
********************************************************************************

*can only download repeat csv data as zip file from moda with group names - will update this code to remove group names
*rename to remove group names - because of the variable length SPSS truncates name
* Note: This syntax file processes the NUT8 adherence indicator by assessing
* whether participants received an adequate number of distributions as per
* program requirements.

RENAME VARIABLES (Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgCard = PNutProgCard).
RENAME VARIABLES (Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgShouldN_A = PNutProgShouldNbrCard).
RENAME VARIABLES (Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgDidNbrC = PNutProgDidNbrCard).
RENAME VARIABLES (Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgShouldN = PNutProgShouldNbrNoCard).
RENAME VARIABLES (Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgDidNbrN = PNutProgDidNbrNoCard).

* define variable and value labels
* Can only download repeat CSV data as a zip file from MODA with group names.
* Will update this code to remove group names.

Variable labels PNutProgCard "May I see participant's program participation card?".
Variable labels PNutProgShouldNbrCard 'number of distributions entitled to - measured with participation card'.
Variable labels PNutProgDidNbrCard 'number of distributions received - measured with participation card'.
Variable labels PNutProgShouldNbrNoCard 'number of distributions entitled to - measured without participation card'.
Variable labels PNutProgDidNbrNoCard 'number of distributions received - measured without participation card'.
* Rename to remove group names.
RENAME VARIABLES (Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgCard = PNutProgCard).
RENAME VARIABLES (Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgShouldN_A = PNutProgShouldNbrCard).
RENAME VARIABLES (Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgDidNbrC = PNutProgDidNbrCard).
RENAME VARIABLES (Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgShouldN = PNutProgShouldNbrNoCard).
RENAME VARIABLES (Nutrition_moduleNutProg_submoduleRepeatNutProgPNutProgDidNbrN = PNutProgDidNbrNoCard).

Value labels PNutProgCard 1 'Yes' 0 'No '.
* Define variable and value labels.
VARIABLE LABELS PNutProgCard "May I see participant's program participation card?".
VARIABLE LABELS PNutProgShouldNbrCard "Number of distributions entitled to - measured with participation card".
VARIABLE LABELS PNutProgDidNbrCard "Number of distributions received - measured with participation card".
VARIABLE LABELS PNutProgShouldNbrNoCard "Number of distributions entitled to - measured without participation card".
VARIABLE LABELS PNutProgDidNbrNoCard "Number of distributions received - measured without participation card".

*create variable which classifies if participant received 66% or more of planned distributions
VALUE LABELS PNutProgCard 1 'Yes' 0 'No'.

do if ((PNutProgCard = 1) & ((PNutProgDidNbrCard / PNutProgShouldNbrCard) >= .66)) OR ((PNutProgCard = 0) & ((PNutProgDidNbrNoCard / PNutProgShouldNbrNoCard) >= .66)) .
compute NutProgRecAdequate = 1.
Else.
Compute NutProgRecAdequate = 0.
End if.
* Create variable which classifies if participant received 66% or more of planned distributions.
DO IF ((PNutProgCard = 1) & ((PNutProgDidNbrCard / PNutProgShouldNbrCard) >= .66)) OR ((PNutProgCard = 0) & ((PNutProgDidNbrNoCard / PNutProgShouldNbrNoCard) >= .66)).
COMPUTE NutProgRecAdequate = 1.
ELSE.
COMPUTE NutProgRecAdequate = 0.
END IF.

Variable labels PNutProgDidNbrNoCard "Participant recieved adequate number of distributions?".
Value labels NutProgRecAdequate 1 'Yes' 0 'No '.
VARIABLE LABELS NutProgRecAdequate "Participant received adequate number of distributions?".
VALUE LABELS NutProgRecAdequate 1 'Yes' 0 'No'.

freq NutProgRecAdequate.
* Frequency table for NutProgRecAdequate.
FREQUENCIES VARIABLES=NutProgRecAdequate.

* End of Scripts.
Loading