econ140_problem_set_1
.pdf
keyboard_arrow_up
School
University of California, Berkeley *
*We aren’t endorsed by this school
Course
140R
Subject
Economics
Date
Apr 3, 2024
Type
Pages
39
Uploaded by ProfLapwingMaster1246 on coursehero.com
econ140_problem_set_1
September 16, 2022
In this cell, please type your name and SID
ECON 140R - Problem Set 1
This material is closely and gratefully adapted from the work of the UC Berkeley EEP/IAS 118
team, including Jeremy Magruder, Sofia Villas-Boas, James Sears, and many other people working
on these materials for EEP118. This is your work. We are in your debt!
INSTRUCTIONS
Please step through this tutorial, copy and paste the code, and run it to produce output. Make
sure to write some sentences at the end in response to the questions in the last section. You will
earn 100% of the credit on this problem set for completing it.
Tips:
• We recommend you walk through Coding Bootcamp 1 and Coding Bootcamp 2 before tackling
this Problem Set. You do not need to turn those in
• Type your name and SID in the field at the top
• When done, got to “File: Download As: PDF via LaTeX” or something similar like “File:
Save and Export Notebook As: PDF.” You want a PDF you can upload to Gradescope
• Navigate to Gradescope and find Problem Set 1 there, and submit your PDF. Follow the
prompts on Gradescope to select fields. If you’re not sure how, ask a friend and reach out to
your GSI
Learning goals
0.1
ggplot2 and visualizations
We started off using
R’s
built-in plot function, which let us produce scatterplots and construct
histograms of all sorts of variables. However, it doesn’t look the best and has some ugly naming
conventions.
ggplot2
will give us more control over our figure and allow us to get as in depth with
it as we want. Check out the Wikipedia page on
ggplot2
for details. The etymology is “gg” for
Grammar of Graphics. There is a “2” involved, but the function itself is
ggplot()
.
GENTLE DISCLAIMER
This notebook asks you to step through these functions in a piecemeal fashion. Don’t be surprised
if the early steps don’t look like much. Also, there is no need to get fancy with graphics. Your
objective should be to see how
ggplot()
works, so that you can create useful visualizations.
1
ggplot2
is part of the
tidyverse
package, so we’ll need to load that in before we get started. Let’s
also use the
sleep75.dta
dataset provided by Jeffrey Wooldridge with his textbook. The dataset
comes from J.E. Biddle and D.S. Hamermesh (1990),
“Sleep and the Allocation of Time,”
Journal
of Political Economy 98, 922-943. If you’re interested in the contents of the dataset, here is the
PDF codebook
at CRAN for all 115 datasets in the
wooldridge
package. The documentation for
this dataset starts on page 130.
This dataset is also available through the
wooldridge
R
package; you can either use the local
copy on datahub, per the code below, or you could switch back to the
R
package, shown in the
commented-out code below.
[21]:
library
(tidyverse)
library
(haven)
# Want to use the wooldridge package instead? Uncomment these 3 rows and
␣
↪
commment out the last row below:
#install.packages('wooldridge')
#data(sleep75, package = 'wooldridge')
#sleepdata <- sleep75
sleepdata
<-
read_dta
(
"sleep75.dta"
)
1
ggplot2 Basic Syntax
Let’s start by getting familiar with the basic syntax of
ggplot2
. Its syntax is a little bit different
than some of the functions we’ve used before, but ultimately it makes thing nice and easy as we
make more and more professional-looking figures. It also plays nicely with pipes!
To start a plot, we start with the function
ggplot()
This function initializes an empty plot and passes data to other plots that we’ll add on top. We
can also use this function to define our dataset or specify what our
𝑥
and
𝑦
variables are.
Try starting a new plot by running
ggplot()
— with no arguments — below. You should get a
blank gray canvas:
[22]:
ggplot
()
2
We get a little bit more if we specify our data and our
𝑥
and
𝑦
variables. To specify the data, we
add the argument
data = "dataname"
to the
ggplot()
function.
To specify which variable is on the
𝑥
axis and which is on the
𝑦
, we use the
aes(x = "xvar", y
= "yvar")
argument.
aes()
is short for “aesthetics” and allows us to automatically pass these
variables along as our
𝑥
and
𝑦
variables for the plots we add.
Suppose we’re interested in using our
sleepdata
to see the relationship between age and the
hourly wage in our sample. Note that economists usually take the natural log of the hourly wage,
or of income or wealth if that were our variable of interest.
The reason is that levels of these
variables clearly reveal heteroskedasticity, variances that in this case get larger as the wage and
other correlated variables increase.
Copy and paste this code into the field below and run it:
3
ggplot(data = sleepdata, aes(x = age, y = hrwage))
[23]:
ggplot
(data
=
sleepdata,
aes
(x
=
age, y
=
hrwage))
Now we have labels on both of our axes corresponding to the assigned variable, and a grid corre-
sponding to possible values of those variables. This makes sense, because we told
R
with
aes()
what our
𝑥
variable and
𝑦
variable are, and then
R
automatically sets up tick marks based on our
data.
We will add geometries (sets of points, histograms, lines, etc.)
by adding what we call “layers”
using a
+
after our
ggplot()
function. Let’s take a look at a few of the options.
4
1.1
Scatterplots
Now let’s add some points! If we want to get a sense of how age and the hourly wage vary in our
data, we can do that by just plotting the points. We can add
(𝑥, 𝑦)
points in what is usually called
a “scatterplot” using the function
geom_point()
.
In spreadsheet programs, for example, Excel
calls this an “X Y (Scatter)” chart.
Since we already declared our two variables, all we need to add
+ geom_point()
to our existing
code after the last parenthesis:
ggplot(data = sleepdata, aes(x = age, y = hrwage)) +
geom_point()
[25]:
ggplot
(data
=
sleepdata,
aes
(x
=
age, y
=
hrwage))
+
geom_point
()
Warning message:
“Removed 174 rows containing missing values (geom_point).”
5
This is a plot of all our points.
This rendering could take a very long time if our dataset were
enormous! Also, note that we were warned that there were rows that contained at least one missing
value, and those got dropped.
1.1.1
Labels
Often we’d like to change the labels from the variable names to a more descriptive label, and
possibly add a title. We can, by adding the
labs()
function to our plot. Try pasting this in below
and running:
ggplot(data = sleepdata, aes(x = age, y = hrwage)) +
geom_point() +
labs(title = "Relationship between age and the hourly wage",
subtitle =
"Nonmissing Sample",
caption = "Note: prepared using Wooldridge's sleep75
data.",
x = "Age (years)",
y = "Hourly Wage ($)")
[29]:
ggplot
(data
=
sleepdata,
aes
(x
=
age, y
=
hrwage))
+
geom_point
()
+
labs
(title
=
"Relationship between age and the hourly wage"
,
subtitle
=
"Nonmissing Sample"
,
caption
=
"Note: prepared using Wooldridge's sleep75 data."
,
x
=
"Age (years)"
,
y
=
"Hourly Wage ($)"
)
Warning message:
“Removed 174 rows containing missing values (geom_point).”
6
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
Related Questions
Contour crafting was invented by a creative genius engineer whose idea was originally focused on constructing molds for industrial parts. He later expanded his thinking to rapid home and building construction to help during storm recovery. Think of it as 3-D printing of a home where electrical, plumbing, utilities, custom electronics, and such are installed as the home is "printed" layer by layer and potentially in one day. Precision computer-controlled near-concrete material is applied layer by layer by an apparatus with material feed, various controls for shaping in three dimensions, electronic connections, and for larger applications it uses lattice-like tower elements for support and control of the configuration. Consider a "CC Apparatus" of the appropriate size for contour crafting an industrial building. The initial cost is $215,000 and may be sold in year t for 0.6^t of the original price. Operating costs are $65,000 the 1st year, increasing by 6% per year. Due to the continual…
arrow_forward
Bob's Building Supplies produced $1 million worth of building supplies in 2017. Bob's $350,000 worth of these supplies in 2017 to the Custom Construction Company, which used them to produce mode homes worth $2 million in 2017. Bob's sold another $400,000 of these supplies in 2017 directly to homeowners, who undertook their own home improvements. Bob's sold the remaining supplies to Eco-Play Playgrounds, which used them to build $750,000 worth of playgrounds in 2018.
Under the spending approach, how much did this economic activity contribute to 2017's GDP?
A) $650,000 in building supplies, $2 million in housing, $750,000 in playgrounds
B) $650,000 in building supplies, $2 million in housing, $0 in playgrounds
C) $1 million in building supplies, $1,650,000 in housing, $0 in playgrounds
D) $400,000 in building supplies, $1,650,000 in housing, $500,000 in playgrounds
E) $400,000 in building supplies, $2 million in housing, $0 in playgrounds
F) $400,000 in building supplies, $2…
arrow_forward
The Return of Detroit City: Enpar manufactures engine parts for Ford using steel as an input. Enpar operates two plants, one in Detroit, MI and one in Greenville, SC. The production functions for the two Enpar plants are:Detroit:
QD= 22SD – 0.25 SD2
Greenville:
QG= 50SG – 0.5 SG2
where QD and QG are the outputs of engine parts (in units) from the Detroit and Greenville plants, respectively. SD and SG are the amounts of steel for the two plants. The firm has 187 units of steel available.How much steel should be sent to Detroit?Enter as a value. ROUND TO THE NEAREST WHOLE NUMBER.
arrow_forward
Sunflower Manufacturing recently applied for a $10 million loan at The Democrat Federal Bank (known simplyas The Democrat). The purpose of the loan is to support its working capital needs (short-term funds) duringthe next nine months. Sunflower has been a loyal customer of the bank for many years and has beenextended whatever amount of credit it requested in the past.Sheli Crocker, who is a new, young loan officer at The Democrat, reviewed Sunflower's loan application anddecided to turn down the loan for the requested amount. In her report to Henry, her boss and the senior loanofficer, Sheli indicated that she thought Sunflower would have trouble repaying a $10 million loan because itsfinancial positions has deteriorated in recent months. Sheli noted that the company's ability to pay its currentobligation - that is, its liquidity position - is poor and that analysts are pessimistic about Sunflower's ability toimprove its liquidity during the next two years. As a result, Sheli…
arrow_forward
Use economic equivalence to determine the amount of money or value of i that makes the following statements correct. (a) $5000 today is equivalent to $4275 exactly 1 year ago at i = ___% per year. (b) A car that costs $28,000 today will cost $____ a year from now at i = 4% per year. (c) At i = 4% per year, a car that costs $28,000 now, would have cost $____ one year ago. (d) Last year, Jackson borrowed $20,000 to buy a preowned boat. He repaid the principal of the loan plus $2750 interest after only 1 year. This year, his brother Henri borrowed $15,000 to buy a car and expects to pay it off in only 1 year plus interest of $2295. The rate that each brother paid for his loan is ___ % for Jackson and ___ % per year for Henri. (e) Last year, Sheila turned down a job that paid $75,000 per year. This year, she accepted one that pays $81,000 per year. The salaries are equivalent at i = ____% per year.
arrow_forward
Dear tutor, please solve the all part of the question as very clear and detailed. THANK YOU SO MUCH!!!
arrow_forward
State the difference between a contingent project and a dependent project.
arrow_forward
Discuss the major features of UN Global Compact.(600-700 words)
(Please don't copy from chatgpt i will thumbs down if you do so)
Can take help from other sources.Thanks :)
arrow_forward
Describe the idea of cost of a life-cycle in your own terms. Why is the life-cycle cost savings opportunity being highest in the life-cycle acquisition phase?
arrow_forward
Plan A
(Depreciation 3422 ; total anual cost 23922)
Plan B
(Depreciation 4277 ; total anual cost 22857)
Plan C
(Depreciation 7071; total anual cost 24, 891)
Plan D
(Depreciation 7413; total anual cost 22533)
All I need is a solution for the question. Our subject is engineering economics and the lesson is economic study method
arrow_forward
I need solve this question in Engineering Economics
arrow_forward
answer with detailed solutions. (1)
arrow_forward
Please both all question solve.. For only project A and B . . Just do for project A and B
arrow_forward
Describe from a technical analysis perspective . If you were an investor what would you read from this char
arrow_forward
SCENARIO:
ACE Manufacturers is a small firm that makes children’s clothing which it sells to a large retail store. Mrs Samuels, who started the business, enjoys managing the operation.The production process involves the designing, cutting, sewing, decorating and finishing of the various items.
Currently the factory space is divided into areas allowing for each of the processes to take place efficiently. The factory facility is rented on a three-year contract basis. Mrs Samuels has recently signed a new contract for another three year period.
Mrs Samuels is keen to correctly identify the different costs in the business and analyse each of the operations to identify whether she is maximising output. In order to do this she requires assistance with understanding the “economics” of the operation.
question
Discuss the different types of costs that this operation will face in the short run. Give appropriate examples in each case.[Hint: Use the economic theory you have studied relating…
arrow_forward
please solve with full detail so I can understand, Engineering Econ
arrow_forward
Define opportunity cost and explain its relevance in engineering project decision-making. Provide a real-world example of how considering opportunity cost can influence the choice between alternative projects or investments.
arrow_forward
In your own words, describe the life-cycle cost concept. Why is the potential for achieving life-cycle cost savings greatest in the acquisition phase of the life cycle?
arrow_forward
Planning for a major redesign, Itumeleng collected data at her store on several consecutive Saturday mornings. She noticed that customers arrived at the checkout at a rate of approximately 100 per hour. Fully 20 percent of the customers had 10 items or less. Those people took about 2 minutes to serve on average, while customers with more than 10 items took about 4 minutes to process. Itumeleng expects service time to improve when universal price code readers are installed in the new design. Help Itumeleng with her design for the system,
arrow_forward
Cindy and Steven are recently married and are both chefs. They have recently graduated from culinary school and are making a starting salary of $15.00 as a sous-chef. They both work 10 hour days, six days a week. Because they are chefs at a mid- level restaurant they live in the downtown core where it is located. The rent on their one bedroom apartment is $1125/month. This includes all utilities. However, they pay an additional $75 for cable and internet. Their joint cell phone bill is $60.00 and they opt not to have a landline to save money. Because they live downtown they have also chosen not to buy a car and spend about $200 a month on public transportation. They eat most meals for free at the restaurant where they work so their grocer bill is only about $200 a month. Do Cindy and Steven earn enough money to cover their expenses
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Managerial Economics: Applications, Strategies an...
Economics
ISBN:9781305506381
Author:James R. McGuigan, R. Charles Moyer, Frederick H.deB. Harris
Publisher:Cengage Learning
Related Questions
- Contour crafting was invented by a creative genius engineer whose idea was originally focused on constructing molds for industrial parts. He later expanded his thinking to rapid home and building construction to help during storm recovery. Think of it as 3-D printing of a home where electrical, plumbing, utilities, custom electronics, and such are installed as the home is "printed" layer by layer and potentially in one day. Precision computer-controlled near-concrete material is applied layer by layer by an apparatus with material feed, various controls for shaping in three dimensions, electronic connections, and for larger applications it uses lattice-like tower elements for support and control of the configuration. Consider a "CC Apparatus" of the appropriate size for contour crafting an industrial building. The initial cost is $215,000 and may be sold in year t for 0.6^t of the original price. Operating costs are $65,000 the 1st year, increasing by 6% per year. Due to the continual…arrow_forwardBob's Building Supplies produced $1 million worth of building supplies in 2017. Bob's $350,000 worth of these supplies in 2017 to the Custom Construction Company, which used them to produce mode homes worth $2 million in 2017. Bob's sold another $400,000 of these supplies in 2017 directly to homeowners, who undertook their own home improvements. Bob's sold the remaining supplies to Eco-Play Playgrounds, which used them to build $750,000 worth of playgrounds in 2018. Under the spending approach, how much did this economic activity contribute to 2017's GDP? A) $650,000 in building supplies, $2 million in housing, $750,000 in playgrounds B) $650,000 in building supplies, $2 million in housing, $0 in playgrounds C) $1 million in building supplies, $1,650,000 in housing, $0 in playgrounds D) $400,000 in building supplies, $1,650,000 in housing, $500,000 in playgrounds E) $400,000 in building supplies, $2 million in housing, $0 in playgrounds F) $400,000 in building supplies, $2…arrow_forwardThe Return of Detroit City: Enpar manufactures engine parts for Ford using steel as an input. Enpar operates two plants, one in Detroit, MI and one in Greenville, SC. The production functions for the two Enpar plants are:Detroit: QD= 22SD – 0.25 SD2 Greenville: QG= 50SG – 0.5 SG2 where QD and QG are the outputs of engine parts (in units) from the Detroit and Greenville plants, respectively. SD and SG are the amounts of steel for the two plants. The firm has 187 units of steel available.How much steel should be sent to Detroit?Enter as a value. ROUND TO THE NEAREST WHOLE NUMBER.arrow_forward
- Sunflower Manufacturing recently applied for a $10 million loan at The Democrat Federal Bank (known simplyas The Democrat). The purpose of the loan is to support its working capital needs (short-term funds) duringthe next nine months. Sunflower has been a loyal customer of the bank for many years and has beenextended whatever amount of credit it requested in the past.Sheli Crocker, who is a new, young loan officer at The Democrat, reviewed Sunflower's loan application anddecided to turn down the loan for the requested amount. In her report to Henry, her boss and the senior loanofficer, Sheli indicated that she thought Sunflower would have trouble repaying a $10 million loan because itsfinancial positions has deteriorated in recent months. Sheli noted that the company's ability to pay its currentobligation - that is, its liquidity position - is poor and that analysts are pessimistic about Sunflower's ability toimprove its liquidity during the next two years. As a result, Sheli…arrow_forwardUse economic equivalence to determine the amount of money or value of i that makes the following statements correct. (a) $5000 today is equivalent to $4275 exactly 1 year ago at i = ___% per year. (b) A car that costs $28,000 today will cost $____ a year from now at i = 4% per year. (c) At i = 4% per year, a car that costs $28,000 now, would have cost $____ one year ago. (d) Last year, Jackson borrowed $20,000 to buy a preowned boat. He repaid the principal of the loan plus $2750 interest after only 1 year. This year, his brother Henri borrowed $15,000 to buy a car and expects to pay it off in only 1 year plus interest of $2295. The rate that each brother paid for his loan is ___ % for Jackson and ___ % per year for Henri. (e) Last year, Sheila turned down a job that paid $75,000 per year. This year, she accepted one that pays $81,000 per year. The salaries are equivalent at i = ____% per year.arrow_forwardDear tutor, please solve the all part of the question as very clear and detailed. THANK YOU SO MUCH!!!arrow_forward
- State the difference between a contingent project and a dependent project.arrow_forwardDiscuss the major features of UN Global Compact.(600-700 words) (Please don't copy from chatgpt i will thumbs down if you do so) Can take help from other sources.Thanks :)arrow_forwardDescribe the idea of cost of a life-cycle in your own terms. Why is the life-cycle cost savings opportunity being highest in the life-cycle acquisition phase?arrow_forward
- Plan A (Depreciation 3422 ; total anual cost 23922) Plan B (Depreciation 4277 ; total anual cost 22857) Plan C (Depreciation 7071; total anual cost 24, 891) Plan D (Depreciation 7413; total anual cost 22533) All I need is a solution for the question. Our subject is engineering economics and the lesson is economic study methodarrow_forwardI need solve this question in Engineering Economicsarrow_forwardanswer with detailed solutions. (1)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Managerial Economics: Applications, Strategies an...EconomicsISBN:9781305506381Author:James R. McGuigan, R. Charles Moyer, Frederick H.deB. HarrisPublisher:Cengage Learning
Managerial Economics: Applications, Strategies an...
Economics
ISBN:9781305506381
Author:James R. McGuigan, R. Charles Moyer, Frederick H.deB. Harris
Publisher:Cengage Learning