# -*- coding: utf-8 -*-
# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .r
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: R
#     language: R
#     name: ir
# ---

# # Big Assignment 2 

# # Exercise 1: Do Microfinance Loans Affect Expenditure?
#
# ### Most of the world's poor have limited access to formal credit. Traditionally, they have had to resort to their social networks (family, friends) or local moneylenders that charge exorbitant interest rates (upwardsof 100%). This often prevents individuals from making investments in potential businesses or productive assets. In the last 15 years, microfinance institutions (MFI) have emerged all across the developing world to address this problem. The basic model of a microfinance institution (such as the Grameen Bank) is to provide small loans to a group of potential borrowers at much lower interest rates. The number of very poor families with a microloan has grown exponentially: from 7.6 million in 1997 to 137.5 million in 2010. Micro-credit has been heralded as a major advance in the reduction of global poverty. However, in recent years, critiques have emerged accusing micro-finance institutions of acting irresponsibly by holding the poor to very strict repayment schedules and charging unreasonably high interest rates. So where does this leave us? Does micro-credit help or hinder? In the January 2015 issue of the American Economic Journal: Applied Economics, six papers evaluating the merits of micro-credit were released. We will explore the results from one of these papers by Augsburg et al., which evaluates a microfinance institution in Bosnia and Herzegovina.

# # Data Description

# ### The data for this exercise comes from a study conducted in Bosnia and Herzegovina investigating the effects of a small loan on access to liquidity; self-employment and income; labor supply; expenditure and savings. These were individual-liability loans with monthly repayments and an interest rate of 22%. The sample consists of potential borrowers (who were just marginally eligible for loans). Approximately half the sample was randomly selected to receive the loan (the treatment group), while the other half did not receive anything (control group). You have a subsample of individuals (both in the treatment and control group) that the researchers used for their analysis. The respondent (= the loan applicant) answered questions about the household they belonged to as well (no two respondents are from the same household). The PS2_MFI.dta file includes the following variables:

# • `treatment` : dummy equal to 1 if the respondent is in the treatment group (which received a loan)
#
# • `resp_female`: dummy equal to 1 if the respondent is female
#
# • `resp_age`: the respondent's age
#
# • `hhmem`: number of household members
#
# • `hhmem_adults`: number of adults in household ($\geq$14)
#
# • `hhmem_children`: number of children in household (<14)
#
# • `hhmem_elderly`: number of elderly in household (>64)
#
# • `total_exp`: total annual household expenditure in Bosnian Convertible Marka (BAM)
#
# • `food_exp`: annual household expenditure on food in BAM
#
# • `nondur_exp`: annual household expenditure on nondurables (rent, fuel, transport, clothes, insurance...) in BAM
#
# • `dur_exp`: annual household expenditure on durables (education, furniture, vehicle...) in BAM
#
# • `temp_exp`: annual household expenditure on temptation goods (cigarettes, tobacco, alcohol) in BAM
#
# ### The prevailing exchange rate at the time of the study was approximately US$1 = 1.63 BAM.

# # Question 1

# Load the dataset `PS2_MFI.dta`. Notice that this is a `.dta` file so you will need to use the `haven` package.

# +
#load the packages and the dataset here. 
# -

# ### a) How many respondents are in your data set? How many respondents are females? What is the mean age among the respondents in the sample? What is the mean number of household members among respondents in your sample?

# +
#Code for Q1a here. Be sure that your code prints out your answers. 
# -

# Double click here to type your answer to part a. 

# ### b) Construct a variable `total_exp_pc` equal to total expenditures per capita in BAM. Plot a histogram (Hint: use the `hist()` command) of this constructed variable. What is the range of household total expenditures per capita? (You may want to refer to US Dollars in the discussion, so as to make sense of the income level of these MFI clients).

# +
#Code for Q1b here. Be sure to add titles to your histogram.
# -

# Double click here to type your answer to part b. 

# ### c) Calculate the proportion of household expenditures spent on non-durable goods (education, furniture, repairs, vehicle, appliances). You will need to create this new variable. What is the mean? What is the median? Compare the mean value of these proportions among treatment and control households.

# +
#Code for Q1c here.
# -

# Double click here to type your answer to part b. 

# # Question 2

# ### We will now explore the role of household size in food consumption. Consider these two models: 
#
# Model 1: $\ln( $ food_exp_pc $ ) = \beta_0 + \beta_1 \ln($ total_exp_pc $) + \beta_2 $ treatment $ + u $
#
# Model 2: $\ln($ food_exp_pc$) = \beta_0 + \beta_1 \ln($total_exp_pc$) + \beta_2$ treatment$ + \beta_3 \ln($hhmem$) + u $

# ### a) Estimate equations (1) and (2).

# +
# Code for Q2a here. Be sure to print the summary() of your regressions.
# -

# ### b) Interpret the estimated parameters of equation (2). The results you are finding on the role of household size may a priori seem suprising. Try to think about a scenario whereby two households of the same size, with the same total expenditures per capita decide to move in together. What does your estimation predict about food consumption per capita?

# Double click here to type your answer to part b.

# ### c) How did your estimate of $\hat{\beta}_1$ change between equation (1) and equation (2)? Without performing any calculations, what information does this give you about the correlation between total expenditure per capita and household size? (Explain your reasoning in no more than 4 sentences.)

# Double click here to type your answer to part c.

# ### d) Predict the expected value of food expenditure of a control household with 3 members and total annual expenditure per capita of BAM 3000 using your estimates from equation (2).

# Double click here to type your answer to part d.

# # Question 3

# ### A country's dependency ratio is the ratio of old and young dependents (dependents are those not in the labor force) to the working-age population. A similar measure could be constructed for the household: 

# $hhdr =\frac{\text{hh members under 14 or over 64}} {\text{hh members aged 14 to 64}}$ 

# ### Model 1 (as well as Model 2) does not capture how the composition of a household, i.e. the characteristics of the members, is associated with food consumption per capita. You suspect that the structure of the family affects food expenditure per capita controlling for the log of household size and the log of total expenditure per capita (think about how children and older people might consume less food than adults; and how larger households might have more children). Specifically you hypothesize that a higher dependency ratio is associated with lower food expenditure per capita.

# ### (a) Write an equation you could estimate that would test this hypothesis.

# Double click here to type your answer to part a

# ### (b) Estimate the equation in part (a). What can you conclude about the hypothesis?



# Double click here to type your answer to part b. 

# # Exercise 2: Perception on Global Warming

# ### Gallup Polling collects information about a variety of topics ( health, environment, political attitudes, education). In March 2018, Gallup conducted a poll to gather information about the perceived onset of global warming among Californian voters. Question: Do you believe that global warming is caused by human activities?

# |  Group      | Number of Observations  | Yes |
# |-------------|-------------------------|-----|
# |  All voters |  1108                   | 697 |
# | Republicans |  382                    | 133 |  
# | Democrats   |  421                    | 375 | 
# | Independents|  305                    | 189 |
#

# ### Consider first the overall result (all voters). Let p be the fraction of voters that believe that global warming is caused by human activities.

#  NNote: You answer to the following questions should not necessarily require any R code (unless you would like to use R as a calculator).  Some of your answers will require that you type in equations. Latex is a typsetting language that makes nicely formatted equations. At the begining and end of an equation you will need to type a $\$$  to tell Jupyter that you are typing a Latex equation. The following website has some simple examples showing you how to format your equations in Latex:  http://www.personal.ceu.hu/tex/cookbook.html . 

# ### (a) Use the survey results to estimate p.

# Double click here to type your answer to part a.

# ### (b) Construct a 95% confidence interval for p. Interpret.

# Double click here to type your answer to part b.

# ### (c) Suppose you want to test the null hypothesis that 85% of Democrats believe that global warming is caused by human activities against the alternative hypothesis that more than 85% of Democrats believe that global warming is caused by human activities. Write down the null and alternative hypotheses. Is this a one-sided or two-sided test?

# Double click here to type your answer to part c.

# ### (d) Generate a test statistic which will allow you to test the null hypothesis that more than 85% of Democrats believe that global warming was caused by human activities, and identify a critical value which will give you 99% confidence.

# Double click here to type your answer to part d.

# ### (e) Implement your test and interpret your results.

# Double click here to type your answer to part e.

StarcoderdataJupyterScriptsDedupFiltered