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).”
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.
Answers to these exercises are available here.
For other parts of this exercise set, follow the tag econometrics.
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.
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.
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.
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.
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.