Manavi Thakur Lab 1 Econ 175

pdf

School

University of Alabama *

*We aren’t endorsed by this school

Course

404

Subject

Economics

Date

Feb 20, 2024

Type

pdf

Pages

12

Uploaded by ChiefHeat13487

Report
1/29/24, 7:26 PM Econ/Demog C175 Lab 1: World Population Growth https://datahub.berkeley.edu/user/mthakur/rstudio/files/econ_demog_c175_2023/labs/lab_01_world_2024.nb.html 1/12 Econ/Demog C175 Lab 1: World Population Growth Overview This is the first lab of Economic Demography (Econ/Demog C175). Our goals in this first lab are: 1. To get everyone started programming and doing their assignments with R, RStudio, and bCourses. 2. To use the exponential model to learn about world population history. This document is written in the “R markdown” format and should be read and edited within RStudio. The notebook interface allows you to execute and display R-code within a single window. You can edit this notebook directly and save it. We recommend you save it with a different name (e.g., “world_lab_1_newname.Rmd”) to avoid overwriting your edits. Viewing note: the labs are formatted using hard line-endings. Try resizing viewing window if lines are overflowing. Writing and executing R commands In the RStudio Notebook, we mix executable R commands in with regular written text by creating a “code chunk.” To open a code chunk, we type ““ {r}" to start. To close the code chunk we type " ”” to end. Here are some examples: To print a string of text, you can hit the green “play” icon to execute the chunk of code: print("Hello, Berkeley") [1] "Hello, Berkeley" Try modifying the chunk so it prints: “Hello, Berkeley”. (Note the [1] just means that it is the first element of the displayed object. You can ignore this.) To add 2 + 2: 2+2 Code Hide Hide
1/29/24, 7:26 PM Econ/Demog C175 Lab 1: World Population Growth https://datahub.berkeley.edu/user/mthakur/rstudio/files/econ_demog_c175_2023/labs/lab_01_world_2024.nb.html 2/12 [1] 4 To assign the value 4 to a variable named “x”: x <- 4 print(x) [1] 4 The output of a chunk is only shown when you tell it to be. For example, x <- 3 print(x) [1] 3 y <- 4 ## note: we don't tell R to show us the value of "y" z <- 5 print(z) [1] 5 Try to modify the above code chunk so it also prints the value the variable “y” Using R to calculate exponential population growth rates Hide Hide Hide Hide
1/29/24, 7:26 PM Econ/Demog C175 Lab 1: World Population Growth https://datahub.berkeley.edu/user/mthakur/rstudio/files/econ_demog_c175_2023/labs/lab_01_world_2024.nb.html 3/12 ## comments (within code chunks) begin with hashtags. They are ignored ## by R. ## We start by inputting world population sizes by hand, assigning ## them to variables named "N.1900" and "N.2000" by using the assignment ## operator: "<-" N.1900 <- 1650 # estimated world population in 1900 (in millions) N.2000 <- 6127 # same for 2000 ## we can display the value of the variable called N.1900 (hit the ## "play" button) print(N.2000) [1] 6127 ## We now calculate growth rate from 1900 to 2000, using our formula ## for the slope of the logarithm of population. ## in R when we write log(), this command will give us the natural log, which uses base e R.twentieth.century <- ( log(N.2000) - log(N.1900) ) / (2000 - 1900) R.twentieth.century [1] 0.0131193 You should get “[1] 0.0131193”, or about 1.3 percent. We can check this answer N.2000.check <- N.1900 * exp(100 * 0.0131193) N.2000.check [1] 6127 Which is “6127”, the correct value for the world population in 2000. Now let’s calculate the exponential growth rate for the fifty years from 1850 to 1900. You need to alter the code below to get the right answer. Hide Hide Hide
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
1/29/24, 7:26 PM Econ/Demog C175 Lab 1: World Population Growth https://datahub.berkeley.edu/user/mthakur/rstudio/files/econ_demog_c175_2023/labs/lab_01_world_2024.nb.html 4/12 Next 1 2 3 Previous N.1850 <- 1262 # these are millions ## Note: We don't need to re-enter N.1900, since variables are saved ## across chunks. ## Now modify the code below to give the right answer. (Hint: you need ## to rename the variables N.2000 and N.1900 and change the dates ## "2000" and "1900".) R.1850.to.1900 <- ( log(N.1900) - log(N.1850) ) / (1900 - 1850) print( R.1850.to.1900 ) [1] 0.00536155 You should get , about 0.5 percent. (Hint: If you’re still getting 0.0131193, it means you haven’t modified the code and have assigned the new variable R.1850.to.1900 with the answer for 1900 to 2000.) (Note: class demo – if given – ends about here.) The complete history of world population First we’re going to read in data from a file that we’ve placed on the course lab website. ## Source: https://en.wikipedia.org/wiki/World_population ## Notes: Population is in millions of people dat <- read.table("https://raw.githubusercontent.com/josh-goldstein-git/econ_demog_c175_ 2023/main/data/world_population_data.txt", header = T) dat year <int> pop <int> -8000 5 1 200 1000 400 1500 458 1600 580 1700 682 1750 791 1800 1000 1850 1262 1900 1650 1-10 of 24 rows 0.00536155 Hide
1/29/24, 7:26 PM Econ/Demog C175 Lab 1: World Population Growth https://datahub.berkeley.edu/user/mthakur/rstudio/files/econ_demog_c175_2023/labs/lab_01_world_2024.nb.html 5/12 NA Look at the data set, which has the form of a table with two labeled columns “pop” and “year”. We’re going to extract the contents into our two vectors year.vec and N.vec. (You don’t need to understand this yet. We’ll be learning about why this works in later labs.) million <- 1000000 N.vec <- dat$pop / 1000 ## converts millions to billions year.vec <- dat$year names(N.vec) <- year.vec Let’s look at both of these year.vec [1] -8000 1 1000 1500 1600 1700 1750 1800 1850 1900 1950 1955 1960 1965 [15] 1970 1975 1980 1985 1990 1995 2000 2005 2010 2015 N.vec -8000 1 1000 1500 1600 1700 1750 1800 1850 1900 1950 1955 1960 1965 197 0 0.005 0.200 0.400 0.458 0.580 0.682 0.791 1.000 1.262 1.650 2.525 2.758 3.018 3.322 3.68 2 1975 1980 1985 1990 1995 2000 2005 2010 2015 4.061 4.440 4.853 5.310 5.735 6.127 6.520 6.930 7.349 Our first plot plot(x = year.vec, y = N.vec) Hide Hide Hide Hide Hide
1/29/24, 7:26 PM Econ/Demog C175 Lab 1: World Population Growth https://datahub.berkeley.edu/user/mthakur/rstudio/files/econ_demog_c175_2023/labs/lab_01_world_2024.nb.html 6/12 Wow, looks like world population is exploding. Let’s see what is happening in terms of proportional changes (by taking logs) log.N.vec <- log(N.vec) plot(x = year.vec, y = log.N.vec) Hide
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
1/29/24, 7:26 PM Econ/Demog C175 Lab 1: World Population Growth https://datahub.berkeley.edu/user/mthakur/rstudio/files/econ_demog_c175_2023/labs/lab_01_world_2024.nb.html 7/12 Wow, it looks like even the proportional rate of growth has increased. You can now guess-timate the exponential population growth rate by eye-ing the “slope” of the log rate of population growth. The slope is equal to the calculated growth rate. For example, the 8000 year period from -8000 to 0 saw an increase of about 4 in log-population size. The slope is thus about 4/8000 = 0.0005. We can check this with our calculations below. Calculating growth rates through history Calculate a vector of exponential growth rate. Here we will use the diff() function in R, which tells us the differences between elements in a vector. For example, x = c(4, 5, 7) ## this is a vector with three elements. diff(x) # gives us the differences between elements [1] 1 2 We’ll formulate this as the slope of the graph of log population sizes Hide Hide
1/29/24, 7:26 PM Econ/Demog C175 Lab 1: World Population Growth https://datahub.berkeley.edu/user/mthakur/rstudio/files/econ_demog_c175_2023/labs/lab_01_world_2024.nb.html 8/12 rise.vec <- diff(log.N.vec) # these are the "rise", the vertical distances between point s run.vec <- diff(year.vec) # these are "run", the horizontal distances between points slope.vec <- rise.vec / run.vec R.vec <- slope.vec R.vec 1 1000 1500 1600 1700 1750 18 00 0.0004610523 0.0006938410 0.0002708093 0.0023615892 0.0016200155 0.0029653662 0.00468914 62 1850 1900 1950 1955 1960 1965 19 70 0.0046539553 0.0053615505 0.0085093155 0.0176529433 0.0180177162 0.0191945302 0.02057781 43 1975 1980 1985 1990 1995 2000 20 05 0.0195946332 0.0178450255 0.0177885388 0.0179989530 0.0153991831 0.0132234966 0.01243382 84 2010 2015 0.0121970875 0.0117408873 Let’s make a bit more readable by expressing the growth rates in percentage points, and rounding them R.vec.in.percent <- 100 * round(R.vec, 4) R.vec.in.percent 1 1000 1500 1600 1700 1750 1800 1850 1900 1950 1955 1960 1965 1970 1975 1980 1985 199 0 0.05 0.07 0.03 0.24 0.16 0.30 0.47 0.47 0.54 0.85 1.77 1.80 1.92 2.06 1.96 1.78 1.78 1.8 0 1995 2000 2005 2010 2015 1.54 1.32 1.24 1.22 1.17 We see that growth rates increased for nearly 10,000 years, but have recently begun to decrease a bit. Plotting the growth rates Let’s try a plot: end.year.each.period.vec <- names(R.vec.in.percent) plot(x = end.year.each.period.vec, y = R.vec.in.percent, main = "Exponential Growth Rates of World Population through the Ages", type = "l") Hide Hide
1/29/24, 7:26 PM Econ/Demog C175 Lab 1: World Population Growth https://datahub.berkeley.edu/user/mthakur/rstudio/files/econ_demog_c175_2023/labs/lab_01_world_2024.nb.html 9/12 It looks like population growth rates have begun to decline. To see a bit better, we can graph only the more recent years plot(x = end.year.each.period.vec, y = R.vec.in.percent, xlim = c(1900, 2020), # limit the x-axis to 1900 to 2020 main = "Exponential Growth Rates of World Population, since 1900", type = "o") Hide
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
1/29/24, 7:26 PM Econ/Demog C175 Lab 1: World Population Growth https://datahub.berkeley.edu/user/mthakur/rstudio/files/econ_demog_c175_2023/labs/lab_01_world_2024.nb.html 10/12 Congratulations You’ve finished all of the computing for the first lab! Graded Questions (Use Gradescope to submit your answers. A guide to using Gradescope is available in this video (https://youtu.be/nksyA0s-Geo) or here (https://help.gradescope.com/article/ccbpppziu9-student-submit- work#submitting_to_your_assignment).) 1. [Multiple choice] Which of the following descriptions is best for the history of human population growth? A. Thousands of years of essentially zero growth, followed by a one time increase in growth rates. B. Alternating lengthy periods of positive and negative growth. C. Constant exponential growth at a rate slightly larger than zero. D. Thousands of years of near zero growth, followed by centuries of accelerating growth, with a recent slowing of growth. print("D") [1] "D" Hide
1/29/24, 7:26 PM Econ/Demog C175 Lab 1: World Population Growth https://datahub.berkeley.edu/user/mthakur/rstudio/files/econ_demog_c175_2023/labs/lab_01_world_2024.nb.html 11/12 2. [A numerical answer] How large would the world population be today if annual growth rates had always been 0.0007 larger for the last 10,000 years? Hint 1: The rules of exponents tell us Hint 2: To calculate exp(10000 * 0.0007), you can use a calculator or any other tool. You don’t have to use R. Hint 3: You should get a population roughly one-thousand (!) times as large as today. Note: Imagine we increased the reproduction rate of each generation by a tiny bit – so, for example, instead of each woman having on average 1 surviving daughter, imagine she had 1.021 surviving daughters. If generations were 30 years in length, then this would mean an increase in the growth rate by about log(1.021/1.00)/30 = .0007. So, the calculation we just did tells us what would have happened to the human population if human fertility and/or survival had consistently been just a tiny bit higher. population <- N.2000 * exp(10000 * 0.0007) population [1] 6719071 3. [A numerical answer] How large would the world population in 2124 be if current exponential growth rates continue? Use 8.0 billion as the population size in 2024 and assume . You can do this calculation however you choose (with R, by hand with a calculator,or any other way.) N.2024 <- 8000000000 N.2124 <- N.2024 * exp(0.01 * 100) N.2124 [1] 21746254628 4. [A short answer.] Do you think this estimate of the world population in 2124 is likely to be too high or too low? Explain your reasoning in a sentence. The estimate of 21,746,254,628 people for the world population in 2124 may be considered too high due to unrealistic assumptions about birth rates, mortality rates, and other demographic factors, potentially overlooking global events like climate change or changes in societal dynamics that could impact population growth. 5. [Optimum Population Exercise] Imagine there’s an island that can only sustain a few people. The marginal product starts at 3 units for the first person, rises to 4 with the 2nd person and then declines by 1 unit for each additional person until the MP of the 6th person is zero. Each person needs to consume 2 units per year to subsist. (Hint: if you are having trouble here with the definitions of the optimum populations, consult the lecture slides.) a. Fill in the Average Product row of the table below. (We recommend you do this by hand to enhance understanding.) exp((R + d) t) = exp(R t) exp(d t) Hide R = 0.01 Hide
1/29/24, 7:26 PM Econ/Demog C175 Lab 1: World Population Growth https://datahub.berkeley.edu/user/mthakur/rstudio/files/econ_demog_c175_2023/labs/lab_01_world_2024.nb.html 12/12 (Hint: The average can be obtained by summing up the marginal product to produce the total product and then dividing by the number of people.) Population Size 1 2 3 4 5 6 7 8 9 10 Marginal Product 3 4 3 2 1 0 0 0 0 0 Average Product 3 3.5 3.3 3 2.6 2.17 1.86 1.63 1.44 1.3 b. What size population gives Sauvy’s economic optimum? 1 c. What size population gives Sauvy’s power optimum? 4 d. What size population is the “maximum” sustainable population? 7 6. [non-graded] About how much time (in hours and minutes) did it take you to complete this lab? Congratulations! You have completed Lab 1.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help