# Do not edit this chunk, but *do* press the green button to the answer key for the quiz info (the unreadable string below)
tot = 0
answer.key = "eJytVsGO2zYQvfsrBr7sbmswtuQkvRTBJjm0QJug2QWKXgrQ0tgiTJFaklrV+foMh5ItrS5B6stiaZLDee/Nm5F4Mm29Q7cRG/gV6O9CFNY5LIKQxnfDxvLDciEqZUK/fOiwRAOV9CB3tg2wWUOttFbWQIO20QjBlvJEt5TxwbVFoC3f3/6CjZYFHakQPt1Dp0IFJ9s6SE/CLYqDWMHN/Q0oA0+tDejvKBT+R/eMjKH6SBn+vH4DNdJFyOAnSuPfNyvoKlVUgE+t1PHnPjEKcAabMdhsDjabguXlWqw3oDxsCJor0IQZquxqqDjSP+gF/G4KRRwHqfVpBRIOznYU0cmAYPewFq+HdJIMC1HadqeVOUBQNZ/ppdmu4YTSUczbj5MjhIlJIq1A28NtdgevFuKLuIMHCx2Cr2yrSwr/TP8j6e1se6j0iTgd3vID20WFxdEn1AR6IQ5ONlXMorFNqxkeVMoH605iLEXOUuRzKfKpFLx8dCeiEwiNVkRpSWTMxMivJgZHuq/lVwJKqPGZKAhV5IDjjoB1pICvSSp0K94bZKqtIwVVOKUjlig4VPGIJGHevs3By44vxN/RB0i0xKslylD5CVdb5mo752o75Wr7vVxtr8bVdsJVIsFLKrL4LhD2BuXxQscIVsZWzuatJ20s3/ew+uUHWzfSxWypfBttQ+Qq0t0XX3x4wDxsF7Y1wb9An12tGfWRHilCcGhKH0+mlMhCHXkrOg5dTZoW5Bok1xCGoAqqH0eVJfe0C5tfXq8FTKOkzCECLqzZ06rEEnanlwWoTOFQepzwmjGvsy6XTbtcv/zD2iPsrUvKNeqI8X1m4mxlxvRuxuO12l8f6XGcwMVAtGDHRCM9IxW3r6RrJoBzBjzrJWljVEi8/Fu62AENlUjMOR2dYbtWN+kjRWyMYi9rKgQGI6GQQdKjtqFWym0mCLg3nEqjXFI4SvOn1KFq/Y2P1W+OZLV3I/w5l2E+N1LaWH7s8edDuVKIs6orJiKVWxw+lNVOljw4qMNTt+r6WdA0aF6WQH41K/WRzu/HOUW5cS8cXM6JOOURbpMLvAqKRhSPoDt6rBy+QdJR+WwVT7E4+IpK6ZLs1d91zPbl9oTOjOmc+SdtjOg8V21pO9NJR9b12jY8QLuor8GD5EccJr/6SjUCfos9303ARaNL722haFkmCrWN5O2UG06JGf0zB958IpJ/TACO1ad2cd8lvdgV4ufEKLmF2CO1s8vBMYs5szgzZd6P1zOLvHxAhL9iEUQV6Z9sBnVmyP8BlWN9bnk4ytgMqMd6+kaJH1Uc8WI4+haTaWxTuHNljlWBPWrNeY8Fddbjin8dLh+sHW6PD55vj0PG22L5DeepzpE="
library(quizify)
source.coded.txt(answer.key)

Overview

Sweden has the longest historical series of reliable vital statistics in the world. The Human Mortality Database, founded at Berkeley, has records for counts of births, deaths, and population size since 1751, well before the demographic transition.

Malthus visited Norway and Sweden and describes his travels in his 2nd edition of (An Essay on the Principle of Population). [http://www.econlib.org/library/Malthus/malPlong7.html#Bk.II.Ch.I]. Please read these two chapters (Book II, Chapter I, “On the Checks to Population in Norway” paragraphs II.I.1 through II.I.8; and Chapter II, “On the Checks to Population in Sweden” paragraphs II.II.1 through II.II.9) for a better understanding about Malthus’s thinking on how the environment and human custom interact to produce demographic outcomes.

In this lab, our goals are:

  1. To assess if the 18th century Swedish series of births and deaths is consistent with Malthusian theory and see if we can detect a weakening of Malthusian regime in the 19th and 20th centuries.

  2. To learn how to use custom functions like malthus.plot.fun() by changing their arguments (without rewriting the functions themselves).

  3. To use the non-graded interactive questions we have written for you (e.g., Q.1.1, Q.1.2).

Note: there are TWO types of questions in Lab 2. First, we have the non-graded interactive questions in the special code chunks (which we did not have in Lab 1). These you do in RStudio. The goal of these is to help your learning of the material, not to assess you. Second, as in Lab 1, we have questions at the end that will be graded. These you submit through Gradescope.

Part 0: Import the data

## Note: you need to run this code to do the lab. But understanding it
## is optional.
## Read in the data from a file on our server
df <- read.table("/data175/SWE_pop_birth_death.txt", header =T)
## Display the first few rows of the object "df"
head(df)
ABCDEFGHIJ0123456789
 
 
N
<int>
B
<int>
D
<int>
175117671636929146902
175217838566497349467
175318020186600743905
175418206426875948645
175518392567000851090
175618557456798752062
## Create a separate object for population size, births, deaths, and year.
## Note: "read.table()" imports as a "data.frame", which stores each
## column of a data set as a separate element, which can be accessed
## with the dollar-sign, as below.
N <- df$N                               # population size
B <- df$B                               # births
D <- df$D                               # deaths
year <- rownames(df)
## Note: N, B, D, and year are vectors. In the last lab we used ".vec" in the names of the vectors. Here we omit this to make our code more readable.

Part 1: Inspect and understand the data

Plot the history of Swedish population size, counts of births, and counts of deaths.

plot(year, N, type = "l")

Q1.1 How big is the population of Sweden in 1800

  1. about 20 thousand

  2. about 200 thousand

  3. about 2 million **

  4. about 20 million

##  "Replace the NA with your answer (e.g., 'A' in quotes)"
answer1.1 = 'C'
quiz.check(answer1.1)
Your  answer1.1 : C
Correct.
Explanation:  2e+06 means 2 * 10^6, which equals 2 million

To get a more readable plot we can change units

million = 1000000
N.millions <- N/million
plot(year, N.millions, type = "l")

Q1.2 What is the average (exponential) growth rate of Sweden from 1751 to 2014.

( log(N[year == "2014"]) - log(N[year == "1751"]) )/ (2014 - 1751)
[1] 0.006452649

Which value is this closest to?

  1. 1 percent

  2. 6 percent

  3. 0.5 percent

  4. 0.005 percent.

##  "Replace the NA with your answer (e.g., 'A' in quotes)"
answer1.2 = 'C'
quiz.check(answer1.2)
Your  answer1.2 : C
Correct.
Explanation:  Yes. Incidentally, a growth rate of 0.5 percent has a
.doubling time of about 140 years. (Doubling time is equal to log(2) /
.R.) So we should have seen roughly 2 doublings, which checks with our
.graph of population history.
# plot of Deaths by year, with type = "line"
plot(x = year, y = D, type = "l")

Q1.3. In what year did Sweden have the most deaths?

  1. In about 2000, because the population age structure shifted to older ages.

  2. In about 1850

  3. In 1773

##  "Replace the NA with your answer (e.g., 'A' in quotes)"
answer1.3 = 'C'
quiz.check(answer1.3)
Your  answer1.3 : C
Correct.
Explanation:  Amazingly even though the population was smaller, the rate of mortality was so high, that 1773 saw the highest number of deaths.

Plot the births using code similar the code for deaths, which is given below.

# This is the code for deaths by year (modify it slightly).
plot(x = year, y = B, type = "l")

Q1.4 When were births at their low?

  1. In the great depression (1930s)

  2. In the low fertility of the economic recession at the end of the 1990s.

  3. In about 1773

##  "Replace the NA with your answer (e.g., 'A' in quotes)"
answer1.4 = 'C'
quiz.check(answer1.4)
Your  answer1.4 : C
Correct.
Explanation:  Amazingly, the same date as peak mortality.

Part 3: Detecting Malthusian dynamics

In class, we showed the two-panel graphical explanation of the Malthusian model. In the upper panel, we showed the relationship between wages and birth and death rates. In the lower panel, we showed the relationship between population size and wages. Together, these two panels create the feedback loop for a very low growth Malthusian economy and population.

Here, we will look at whether one part of the Malthusian world appears to hold: that births and deaths go in opposite directions in good and bad times. We don’t have a measure of wages, so our inference is going to be indirect, looking at the relationship between births and deaths by year.

Q3.1. What relationship between births and deaths would be consistent with a Malthusian economy

  1. As births go up, deaths go up

  2. As birth rates go up, deaths rates go up

  3. As births go down, deaths go up

  4. As birth rates go down, death rates go up.

##  "Replace the NA with your answer (e.g., 'A' in quotes)"
answer3.1 = 'D'
quiz.check(answer3.1)
Your  answer3.1 : D
Correct.
Explanation:  In a bad times, death rates would rise (the positive check) and people would avoid having children (the preventive check).
malthus.plot.fun <- function(from.year, to.year)
{
  ## a scatter plot of crude birth and death rates
  ## note: this function assumes that cdr and cbr already exist.
  ## If you're having problems, try running the code chunk above
  ## that creates the cbr and cdr
  my.years <- from.year:to.year
  s <- year %in% my.years
  plot(cdr[s], cbr[s], type = "n",
       xlab = "Crude death rate", ylab = "Crude birth rate")
  abline(lm(cbr ~ cdr, subset = s))
  text(cdr[s], cbr[s], year[s], cex = .5)
  my.cor <- round(cor(cdr[s], cbr[s]), 2)
  title(paste("Birth and Death Rates in Sweden, from", from.year,
              "to", to.year, "\n Correlation:", my.cor))
}
## now let's plot the first 50 years
malthus.plot.fun(from.year = 1751, to.year = 1800)

Q3.2 Which of the patterns in Q3.1 (A,B,C,or,D) does this match most closely?

##  "Replace the 'NA' with your answer (e.g., 'A' in quotes)"
answer3.2 = 'D'
quiz.check(answer3.2)
Your  answer3.2 : D
Correct.
Explanation:  Higher mortality rates are in years with lower
.fertility rates

Q3.3 Is the pattern seen from 1751 to 1800 consistent with Malthusian theory?

A. Yes

B. No

##  "Replace the 'NA' with your answer (e.g., 'A' in quotes)"
answer3.3 = 'A'
quiz.check(answer3.3)
Your  answer3.3 : A
Correct.
Explanation:  Our data is consistent with Malthus's idea that in bad times birth rates fell and death rates rose, and that in good times death rates fell and birth rates rose.

We see that birth rates are low when death rates are high (e.g., in 1772 and 1773). Even if we ignore these unusual years, there is a generally negative relationship. Now plot the relationship for the following time periods.

1801-1850

## Modify the code we used for 1751 to 100 appropriately.
malthus.plot.fun(from.year = 1801, to.year = 1850)

1851-1900

## Modify the code we used for 1751 to 100 appropriately.
malthus.plot.fun(from.year = 1851, to.year = 1900)

1901-2014

## Modify the code we used for 1751 to 100 appropriately.
malthus.plot.fun(from.year = 1901, to.year = 2014)

Part 4: Lab write up. Please limit each answer to 50 words or less.

1. Turn in your plot of the relationship between birth and death rates from 1801-1850.

malthus.plot.fun(from.year = 1801, to.year = 1850)

3. What does Malthus say is the main determinant of birth rates in Norway? (Hint: see II.I.3 and subsequent paragraphs in the reading). Would this suggest that births would fall in the same year as deaths would rise, or a year or two after?

Malthus basically says that in Norway, the main determinant of birth rates is (whether by law or by custom/tradition) guaranteeing that a man has enough means to support a wife and family. He notes that “positive checks to its population have been so small, the preventive checks must have been proportionably great”. Even if a man doesn’t have to receive a certificate signifying his readiness, often the priest would not honor the marriage request if the man does not likely have enough to support a family. For Norway around this time, it was mostly the aspect of having a place to live and raise a family that limited/determined marriages and thus birth rates.

For contemporary Norwegians, it most likely means that should deaths rise in a given year, vacancies in houses would start opening up, and many males would have a place to start a family. Given that most males have been simply waiting for an open house (and already have all other means), this should mean that the birth rate should increase in a year (after marriage and a bit over 9 months).

Questions 4 and 5: Ireland and the Potato

Potatoes are relatively easy to grow and can be stored year-round to provide a nutritious source of food even in wintertime. In the late 18th century, the introduction of the potato as a staple crop changed the agricultural economy of Ireland by increasing the amount of food that farmers could produce and store. In Malthusian terms, this can be represented as an increase in the wage at every population size ; a shift in the wage curve. (If it’s helpful, think of “wage” as calories ; at a given population size, the land can now provide more calories per person.)

In the Malthus app found at http://shiny.demog.berkeley.edu/josh/new_malthus/ , we can simulate this by moving the wage level from its default of 1 to a higher level, such as 1.18. Do this, and then click “play” (small blue triangle at the bottom of the page). Note that in the app, the “short term” consequences of a shift begin at the vertical dotted line at time zero. Use the simulation to answer the following questions:

4. Describe in words what happens in the short term as a result of the introduction of the potato. What happens to wages immediately after the potato is introduced? What happens to birth and death rates? (Describe the direction of change ; you don’t have to give precise numbers.)

In our simulation, we use w’(N) = 1.3 to signify the increased “wage” of the introduction of the potato as a staple crop, and we evaluate the short term consequences. We see that at the introduction of potato causes wages to increase (linearly) sharply in the short-term. (However it goes back down to the original value over the long run.)

In the short-term, at the introduction of the potato, the birth rate sharply increases and the death rate sharply decreases. After the introduction of the potato,

5. According to Malthus, in the long term, should the population of Ireland return to its initial size? Why or why not?

According to Malthus, in the long run, we might expect the population to return to its initial size (given a constant technology level and economy). However, Malthus tells us that the wage should return to the original equilibrium, which should then drive (or coincide with) an increase the population.

Take the introduction of potato as a staple crop as a substantial technological advancement. We should expect a stronger economy of higher populations and higher wages, which then implies a higher long term “equilibrium” population solely based on this change (introduction of potato).

Questions 6 to 8: pen-and-paper questions

6. On a separate sheet of paper, draw your own Malthusian graph system. (We recommend drawing by hand, as you may be asked to draw this kind of graph on the exams without the aid of a computer.) The top graph should show birth and death rates as a function of wages; the bottom graph should show population size as a function of wages. Label all of the axes and mark the equilibrium state on both graphs by marking b, d, w, and N (equilibrium birth rate, death rate, wage rate, and population size) on the appropriate axes.

Drawing attached and submitted to Gradescope.

7. Imagine that marriage norms change and people start getting married at later ages. This results in a lower birth rate at every wage level. Show this change on your graph by drawing a second, dotted, birth rate line. Mark the new equilibria as b’, d’, w’, and P’. Describe in words what happened to the equilibrium wage level and population size.

Drawing attached and submitted to Gradescope.

The equilibrium wage level due to this change is higher than the original equilibrium wage level (w’ > w). The population size due to this increased wage level is lower than the original equilibrium population (P’ < P).

(Optional: check your pen-and-paper answer of 7 using the Malthus App.)

8. Imagine that a new group of immigrants arrives. Their technologies and social behaviors are identical to the natives. Describe in words what affect this would have. Would it cause a curve to shift, or a temporary move along one of the curves? Which curve, and in which direction would the shift or move be?

Assuming land as a resource is fixed and these immigrants add to the labor force, we can model this equivalently as an abrupt increase in the original population. We should expect a temporary move along the curves, with the increased population size (N’) determining the new (lower) wage (w’).

For birth rates, a lower wage along the curve implies a lower birth rate. For death rates, the new lower wage implies a higher death rate. (Both temporarily.)

9. [non-graded] About how many hours did it take you to complete this lab?

~ 3 hours; 6 hours if including reviewing the reading materials.

Congratulations! You have completed Lab 2.

LS0tCnRpdGxlOiAiRWNvbi9EZW1vZyBDMTc1IExhYiAyOiBNYWx0aHVzIGluIFN3ZWRlbiIKb3V0cHV0OiBodG1sX25vdGVib29rCi0tLQoKYGBge3J9CiMgRG8gbm90IGVkaXQgdGhpcyBjaHVuaywgYnV0ICpkbyogcHJlc3MgdGhlIGdyZWVuIGJ1dHRvbiB0byB0aGUgYW5zd2VyIGtleSBmb3IgdGhlIHF1aXogaW5mbyAodGhlIHVucmVhZGFibGUgc3RyaW5nIGJlbG93KQp0b3QgPSAwCmFuc3dlci5rZXkgPSAiZUp5dFZzR08yellRdmZzckJyN3NibXN3dHVRa3ZSVEJKam0wUUp1ZzJRV0tYZ3JRMHRnaVRKRmFrbHJWK2ZvTWg1SXRyUzVCNnN0aWFaTERlZS9ObTVGNE1tMjlRN2NSRy9nVjZPOUNGTlk1TElLUXhuZkR4dkxEY2lFcVpVSy9mT2l3UkFPVjlDQjN0ZzJ3V1VPdHRGYldRSU8yMFFqQmx2SkV0NVR4d2JWRm9DM2YzLzZDalpZRkhha1FQdDFEcDBJRko5czZTRS9D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