-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnsu.conversion.Rmd
More file actions
93 lines (62 loc) · 4.04 KB
/
nsu.conversion.Rmd
File metadata and controls
93 lines (62 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
title: "nonstandardunits"
author: "Kevin Tang"
date: "11/11/2020"
output: html_document
---
> Packages
```{r}
library(epiDisplay)
library(magrittr)
library(foreign)
library(psych)
library(tidyverse)
options(digits=2)
```
>Data
```{r}
ihs4 <- read.csv("/Users/kevintang/Documents/ihs4/data/ihs4/hh_mod_g_clean.csv")
nsu.factors <-read.csv("/Users/kevintang/Documents/ihs4/data/nutrient.supply/nsu.factors.csv")
hh_id <- read.csv("/Users/kevintang/Documents/ihs4/data/ihs4/hh_mod_a_filt.csv")
```
>Convert Non-Standard Units to KGs
Objective: to convert all food consumption quantities reported in NSU into KGs consumed of each food item.
Background: The first chunck of code converts the HCES food consumption data from both standard (e.g. mL, L, g) and non-standard units (e.g. buckets, pieces, heaps) into kilograms in order to compare consumption of food items between households. Non-standard unit (NSU) conversion factors = the mass (in kg) of one unit of each food item (e.g. a small bucket in Malawi = 2.5L, 2.5L of maize flour weighs 1.2kg). Each food item-unit combination requires a NSU conversion factor.
The World Bank LSMS team provided NSU conversion factors for a number of different food items disaggregated by region (sizes of buckets in Malawi may vary depending on the region). We prioritized these World Bank NSU factors, where I tried to maintain the WB data as in-tact as possible (i.e. maintain regional factors and applying them according to the region the household was located) but it did require some cleaning (e.g. a bucket of pearl millet in the S weighs 0.002 kgs).
There were a lot of missing food-unit factors that the WB factors did not provide. This required either measuring the volume of these NSUs (which we purchased last time we were in Malawi) or educated guesses using the LSMS market photo guide and comparison to USDA mass data for each food item to determine the mass of each NSU for each food item. These estimated NSU factors were applied equally across all three regions.
Data on the NSU factors were compiled into a data file with each NSU factor labeled with a unique "measure_id" which is a combination of the food item code and the measurement unit id code.
Definitely not a glamorous part of the analysis and I assume this is the part that deters a lot of people from using HCES in the first place since it is tedious, time-consuming and very uninteresting.
> Create data frame
1. Label households by region
Food consumption data and geographic region data are located in different parts of the survey. Bring the two pieces of information together and merge.
```{r}
region <- hh_id %>% select(case_id, region)
ihs4 <- merge(x=ihs4, y=region , by.x='id', by.y='case_id', fill=-9999, all.x = TRUE) %>% arrange(item_code) %>% arrange(HHID)
```
2. Merge food-unit specific NSU factor
Merge in the NSU factors according by food item based on what NSU unit each household reported consuming that food item by. Maintain the variation in unit volumes/mass by region.
```{r}
ihs4 <- merge(x=ihs4, y=nsu.factors , by.x='measure_id', by.y='measure_id', fill=-9999, all.x = TRUE) %>% arrange(item_code) %>% arrange(id)
```
3. Create a variable selecting the appropritate NSU factor based on the HH reported region
```{r}
ihs4$ihs4factor_n <- ifelse(ihs4$region == 1, ihs4$ihs4factor_n, NA)
ihs4$ihs4factor_c <- ifelse(ihs4$region == 2, ihs4$ihs4factor_c, NA)
ihs4$ihs4factor_s <- ifelse(ihs4$region == 3, ihs4$ihs4factor_s, NA)
ihs4$factor <- rowSums(ihs4[,c("ihs4factor_n", "ihs4factor_c", "ihs4factor_s")], na.rm=TRUE)
ihs4 <- ihs4 %>% select(-ihs4factor_n, -ihs4factor_c, -ihs4factor_s)
```
4. Calculate the quantity of each food item consumed in Kg
(Quantity of the food item consumed in the NSU) X (NSU factor)
```{r}
ihs4$cons_kg <- ihs4$cons_quant * ihs4$factor
```
5. Convert to quantity consumed per day
IHS4 conducted a 7-day recall. To calculate total consumed per day, just divide by 7.
```{r}
ihs4$kg_d <- ihs4$cons_kg/7
```
> DONE: archive
```{r}
write.csv(ihs4, "/Users/kevintang/Documents/ihs4/data/ihs4/hh_mod_g_processed.csv")
```