Applied Economic Analysis With R – Part 1: Exercises

April 15, 2018
By

(This article was first published on R-exercises, and kindly contributed to R-bloggers)

R has great potential in Economic data analysis, as well as econometrics. In this set of exercises, we will go through a wide variety of topics in econometrics, including wage equations, growth regressions, dynamic regressions and time series models, hedonic regressions, the demand for health care, and labor force participation. In the first set of exercises, we will start with using basic functions to calculate statistical measures and visualizations.

For some of the exercises, we will use the AER package from CRAN, which is a educational package for the book “Applied Econometrics by Christian Kleiber and Achim Zeileis (2008).”

install.packages("AER")
library(AER)

For this set of exercises, we will load and use a data-set available in the AER package called CPS1985. CPS1985’s data-frame has 534 observations and 11 variables, including wage, education, experience, age, ethnicity, region, gender, occupation, sector, union, and marriage. The first variables are numerical and others are factors.

data("CPS1985")
str(CPS1985)

Answers to these exercises are available here.

For other parts of this exercise set, follow the tag econometrics.

Exercise 1
In the first exercise, we will calculate simple statistics of wage in the CPS1985 data-frame. First, use the summary function to see the summary statistics of wage; then, calculate mean, median, variance, and standard deviation of the wage.

Exercise 2
Graphical illustration of statistics would be also helpful. Since wage is numerical, histograms (density plot) and box-plots would be helpful. In this exercise, create a histogram for a wage parameter in the CPS1985 data-frame.

Exercise 3
As for categorical variables, it is not possible to calculate mean and variance. Instead, we can produce frequency tables, bar-plots, and pie charts. In this exercise, use a table function to produce a frequency table for sector and occupation variables. Along with these, produce bar-plots and pie charts for these variables.

Exercise 4
It would also be useful to see the relationship between two categorical variables. In this exercise, consider the gender and occupation variables. Use the xtabs function to show the contingency table, then use the plot function to plot a bar-plot showing gender proportion for each occupation type.

Exercise 5
In this exercise, first calculate the correlation between wage and education to investigate how wage changes by education, then calculate the mean wage for each gender. Finally, compare the wage between males and females using box-plots and qq plots.

To leave a comment for the author, please follow the link and comment on their blog: R-exercises.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)