ECON*3740 INTRODUCTORY ECONOMETRICS FALL 2021 Assignment 1: Basics of R
Studio DUE DATE: September 24 2021 Note on what to submit In some cases I
will ask you to submit your program, sometimes the output, and
sometimes plots or histograms. What I don’t want you to submit is the
contents of the Console window. Suppose the question is as follows: Find
the data file called forest.csv and write an R program to read it in,
compute and write the mean rate of deforestation to a text file, and
generate a plot showing deforestation against population density. Submit
your program, your output file and your plot. What I am looking for is
the following: Program: # REMOVE ALL OBJECTS IN MEMORY
rm(list=ls(all=TRUE)) # READ IN DATA data=read.csv(file=”forest.csv”,
header=TRUE) # REPORT MEAN POP DENSITY sink(“popden.txt”) cat(“The mean
population density is “, mean(data$Pop.den..people.per.000.ha..),”n”)
sink() # PLOT DEFORESTAION vs POP DENSITY
plot(data$Deforest….forest.lost.per.year. ~
data$Pop.den..people.per.000.ha.., xlab=”Population Density”,
ylab=”Deforestation”, pch=16) popden.txt file: The mean population
density is 639.427 Plot: 2 What I am not looking for is the content of
the console window in R studio (bottom left): 3 That part of the screen
is your workspace. But don’t copy and paste what’s in it if I have asked
for a program file or an output file. The reason is that part of the
skill of programming is being able not only to do calculations, but to
go back later and re-do the exact same calculations and make sure the
answers are preserved somewhere. To do that you need to have a working
program in a saved file which writes the important results to an
external file you can also save. The console window shows what’s going
on during your session but it’s not a saved input or output file. 1.
[10] Find the ORANGE.XLS data set and re-save it as a CSV file. Write an
R program to a. read the CSV data set, b. make a scatter plot of the
price of regular oranges (y axis) against the price of organic oranges
(x axis). Make the graph presentable by putting informative labels on
the axes and giving it a title. c. plot a histogram of the prices of
organic oranges using the col=”gray” option. Submit your R program and
the two graphs. 2. [10] Use the dataset EDUC.XLS from the Koop archive
and convert it to a CSV file. It contains data on expenditure on
education (EDUC), GDP and Population for 38 countries around the world.
Write an R program to read the data, make an X-Y scatter plot showing
Education spending versus Population and then compute and write to an
output file a. the correlation between Education spending and GDP as a
sentence “The correlation between education spending and GDP is x”. b.
the covariance between GDP and Population as a sentence “The covariance
between GDP and population is x” Submit your R program, the output file
and the graph. 3. [20] Obtain the file HPRICE.XLS and convert it to a
CSV file. Write an R program that reads the data, then writes the
following to an output file: a. the mean of house prices compared to the
mean after trimming 5% from each end of the sample b. the mean of the
lot size of the first 20 observations in the sample c. the correlation
between house price and lot size (make sure to verify that the answer
matches the one on page 18 of the textbook) Submit your R program and
the output file.