Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

UA 323

Development Economics

Problem Set 5

Due: April 11

●  Remember to include your name on your independently written-up solutions.

●  You should feel free to work with classmates (and use readings/slides/etc. for help), just please write the names of who you worked with

●  Submit your solutions to the Brightspace before class starts. No need to bring a hard copy.

●  Show your work. Include brief and precise explanations of intuition and derivations as appropriate. You do not need to include your code (unless the question explicitly asks for you for the code). But you should save your script.

1    Randomization and Luck

In class, I vaguely mentioned that you can get unlucky” when you randomize, and I want to go over that a bit more.  So let’s think of a really simple experiment:  we are interested in understanding the effect of a placebo on height.  Thankfully, Rafael Irizarry has provided some teaching datasets including one with heights (in inches). Enter the following code to load the dataset.

install .packages("dslabs")

library(dslabs)

data("heights")

df  =  as_tibble(heights)

Here is conceptually what we are doing.  We are going to randomize the students into treatment and control. We are then going to give the treatment students the placebo, and nothing to the control students. After a year, we measure their heights.

1.  First, let’s do one randomization.  We want to randomize students into zero or one with probability .5, which we can do with the rbinom() command. Type

df\$random  <-  rbinom(n  =  nrow(df),  size  =  1,prob  =  .5)

to create a new column that’s random (0,1) with probability .5

Now it’s a year later. Let’s see if the placebo worked. Run a regression predicting height using random using the lm() command.1

What coefficient do you get for random? You don’t have to type out the whole thing, just a few digits.

2.

Now do it again - overwrite the random column with the exact same

df\$random  <-  rbinom(n  =  nrow(df),  size  =  1,prob  =  .5)

command and run the exact same regression  (so the thought experiment is we go back in time,  re- randomize, and then see what happens a year later). What coefficient do you get for random?

It’s different! Which seems bad - we would like our work to be reproducible. For instance, if you tell me that you randomized a group into treatment and control, I would like to be able to verify that you did the randomization correctly. It turns out that R doesn’t make a truly random number, but something that can be reproduced. The relevant thing here is called the seed:” if you know the seed, then you can exactly get the same random values in a systematic way.

Set the seed. You can pick whatever seed you want (google if you don’t know how to set a seed in R).

We’re now going to want to randomize this many many times. The way to automate this is to start by defining a function. Type:

mySimulation  <-  function()  {

df$random  <-  rbinom(n  =  nrow(df),  size  =  1,prob  =  .5)

lmfit  <-  summary(lm(  height  ~  random,  df))$coefficients[2,1]

return(lmfit)

}

What this does is calls a function mySimulation() which rst creates the random column random, and then runs the regression, and then prints the coefficient on random.

If you run mySimulation() over and over it will give you a different answer each time, but that’s good: once you set a seed, the path of estimated placebo coefficients will be the same, even if the specific value changes each iteration.  So now what we’re going to do is run mysimulation 10000 times, in order to get a sense of the distribution of coefficients of the placebo on heights.  This is called a Monte Carlo simulation, and its invention was crucial to the development of the atomic bomb, which is a little higher stakes than this problem set.

A way to do this in R is with the sapply function. This is a helpful website walking through sapply for functions: https://r-coder.com/sapply-function-r/

(If you want to use a different function that’s totally ne for me - there are lots of ways to do this in R)

3.  Create a vector with 10000 elements called MCplacebo in which each cell is one run of mySimulation(). Write down the code you used in order to create MCplacebo

Depending on how you do this question, it may be a really wide vector, which isn’t super convenient. t() will transpose it to a column, and then we can use as tibble() to make a dataframe.

MCplacebo  <-  t(MCplacebo)  %>%

as_tibble()

4.  What’s the distribution of estimated coefficients?  You could show this with a histogram (or a kernel density plot if you want to be fancy)

5. Hopefully your distribution is centered around zero. But what do the tails (the upper and lower extremes) tell us about getting unlucky?”

6.  Remember the thought experiment: we gave some students the placebo, then measured their heights a year later.  Obviously the treatment didn’t affect their actual heights, although in your previous question hopefully you wrote about how sometimes it might have looked like it did. What additional data might you want to collect in order to minimize the chance of getting unlucky (This is also not something we’ve talked about in class, so describe your intuition).

2    Permanent Vs. Transitory Shocks

This section is based on Christina Paxson’s paper Using Weather Variability to Estimate the Response of Savings to Transitory Income in Thailand  (1992).   Please familiarize yourself with the paper moving on.   There is a csv in the assignment folder on Brightspace, which you will want to load into R called paxson corrected, and an associated codebook (which tells you what each variable name means in english).

7. Paxson (1992) attempts to estimate the marginal propensity to save out of transitory income. She states, “finding that these marginal propensities are high would indicate that farmers do use savings to smooth consumption.” Explain the intuition for why this is true

Paxson only has data on total income (the variable inc).  She wants to decompose it into a permanent income component (call it incperm) and a transitory income component (call it inctrans). For the following questions, you will need to replicate the results in Table 3 of Paxson (1992) and obtain estimates of incperm and inctrans

8.  Explain the logic of Table 3 - what exactly does Paxson do to get a permanent” measure of income?

Using the dummies” package (that you will have to install and then load into your library), add to your dataframe dummy variables for region and year, you will need these for the regression

Using the lm” command, run table 3 column 1. The way I would do it would be to create a dataframe called irdat that contains only the relevant variables (so inc, the rainfall variables, the education variables, the xed effects you just made, and so on). Then you can run the regression

ir  <-  lm(inc  ~  . ,data=irdat)

Using the coefficients estimated in the regression for Table 3, Column 1, Paxson constructs a predicted value for permanent income as follows. She multiples the permanent characteristics by their respective coefficients, and adds them up to form incperm (see equation 2 on page 17 of the paper.) Generate the variable incperm.

Here’s how I would do this:

You can store the summary() of a linear model, then use coef() to generate a table of coefficients. To get a specific coefficient, use coef(reg sum)[‘’x”,“Estimate”].

Make a dataframe just of the permanent variables, call it permvars

num_pv  <-  length(permvars)

INCPERM  <-  0

for  (i  in  1:num_pv)  {

thisvar  <-  permvars[i]

INCPERM  <-  INCPERM  +

coef(betas)[thisvar,"Estimate"]*irdat[,c(thisvar)]

}

I put INCPERM in caps because you will want to put it in a dataframe, and I’m not giving you hints about that since you should know how to do it.  Eventually you are going to want to run a regression of savings on income, so be thoughtful about exactly how you do this, since you will also want to include the controls of Table 4 column 1.2

9.  What is the standard deviation of incperm? Also, explain what the function is doing, row by row.

10. Do something similar to create a variable of transitory income, inctrans. What is the standard deviation of inctrans?

11.  Paxson also has a category called unexplained income, defined as inc incperm inctrans. Form this variable and call it incunexp. What is the standard deviation of incunexp?

You will now run a regression to estimate the effect of income on savings. Use the variable save2 as your measure of savings. So the x variables are the three measures of income that you made, and the contols from footnote 2.

12.  What do you estimate for the marginal propensity to save out of each additional dollar of permanent income? What do you estimate for the marginal propensity to save out of each additional dollar of transitory income? Do the magnitudes align with the theory?