Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Problem Set 2 - EC420

See Syllabus

See syllabus for due date.  Turn in a knitted .pdf only on D2L.

This assignment is designed to cover topics from Single Variable Regression.  In this problem set, you will calculate the necessary moments (statistics) to construct an estimate of β1  in a single variable regression. At the end, we will also use R’s built-in OLS function, lm() to compare answers.

To get started:

•  Use the Problem Set template from D2L

•  Save the template in a proper folder for this problem set and name it appropriately (Your last name, and PS2)

•  For each of the numbered main headers in this document, create a main header in your markdown document using a double ##, as shown in the template.

• When there are subquestions (e.g. “A” and “B”), then use triple ###’s, as shown in the template.

• When the blue Question appears, make sure you answer the question in writing after your coding chunk.

As you work, click ‘knit’ in the toolbar to make sure your document renders. Check often so you catch any errors early!

Problem set is out of 65 points

1.  Setup your document

A. Load libraries (2 points)

Using the the chunk labeled q1A in the template, load the following packages and data:

• wooldridge

• knitr

• wage2 data from the wooldridge package

B. Set the sample (2 points)

We are interested only in the data for people with a high school education.  Subset wage2 to keep only those where educ==12.  Save the subsetted data as wage2 (which will replace the full dataset in R’s memory – of course, it won’t replace the original version from the wooldridge package)

2.  Single Variable Regression

We want to examine the relationship between work experience and wage, which we will do with the wage2 dataset from the wooldridge package which you loaded in the previous question 1A.

We will start by plotting the relationship, then we will calculate the β1  in the sample regression equation:

wagei  = β0 + β1 experi + εi

A. Plot the relationship (5 points)

Note: from here on you, you need to create the chunks in your document.

In a code chunk labeled 2A, use the plot command to plot experience (exper) on the x-axis and wage (wage) on the y-axis.  The syntax for the base-R plot command is plot(x,  y) where x and y are numeric vectors of the same length (like columns from the dataset).

Question:  Does there seem to be a relationship in the data between experience and wage?  If we were to “eyeball” a line, would it be upward sloping or downward sloping?  What does economic theory tell us we should expect?

B. Calculate wage and exper (2 points)

In a new code chunk labeled 2B, create an object called wagebar and experbar that holds the mean of wage and exper, respectively.

Question: What is the mean of wage?

C. Calculate the sample variance of exper (2 points)

Using the vector wage2$exper and experbar, create a new column in wage2 equal to exper-experbar.  Then use that vector to calculate the sample variance of exper and save that in an object called svar_exper. Use print(svar_exper) to show the result in your output.

Question: What is the sample variance of exper?

D. Repeat 2B and 2C, but for wage (2 points)

Repeat the process in 2C, but for wage instead of exper.  Calculate the sample variance of wage, but note that we will not need to use it.

E. Calculate Cov(wage, exper) using the results from 2B and 2C (4 points)

Save the covariance as cov_wage_exper.  Consult your lecture slides if you do not recall the formula.  You can do this calculation in as little as one line in R.

Question:  Report and interpret the covariance.   Is  the  covariance  between  exper  and  wage  positive or negative?

F. Calculate β(ˆ)1  (6 points)

Using 2E and 2C, calculate the value of β(ˆ)1  and save it in an object called beta1hat

Question: What is yourβ(ˆ)1 ? What is the interpretation of the coefficient in terms of the population regression

function?

G. Calculate β(ˆ)0  (2 points)

We can do this easily if we remember that the following is always true:

y(¯) =β(ˆ)0 + β(ˆ)1 x(¯)

We know x(¯) (it is experbar), and we know y(¯) (it is wagebar).  You have estimated β(ˆ)1 .  It’s just a matter of solving for β(ˆ)0. Do so, and save the result as beta0hat

Question: What is your β(ˆ)0 ? What is the interpretation of the coefficient in terms of the population regression

function? When does y(¯) =β(ˆ)0 ?

3.  Goodness of Fit

In this section, we will calculate the R2  of the regression from 2.

A. Calculate the Sum of Squares Total (SST) (2 points)

The SST is a measure of the total variance of the dependent variable – the variable we are trying to explain with our independent variable. Using the formula from our lecture notes, calculate the SST and call it SST

Question: What did you calculate for the SST? It might be a very big number - it’s summing over our whole sample and we have a lot of individuals in our sample.

B. Calculate the residuals u(ˆ) from the regression in 2 (4 points)

Calculate u(ˆ)i  for each observation using our estimate of β(ˆ)0  and β(ˆ)1.  Create a new column in wage2 equalt to

residual. What is the mean of the residuals?  Keep in mind, when R gives you something like 1.5e-10, it means (1.5x10  10 ) or .00000000015.

Question: What is the mean of the residuals? Is this a strange result, or did you expect this?

C. Calculate the SSR (4 points)

With wage2$residuals containing the u(ˆ), you can calculate the Sum of Squared Residuals (or SSR).  Save

this in an object called SSR

Question: What is the SSR? Is this larger or smaller than the SST? Can it ever be larger than the SST?

D. Calculate the R2  (2 points)

Using the formula in our lecture notes, calculate the R2

Question: Report and interpret that R2  in the context of our regression.

4.  Calculate the Standard Error of the estimate

With our estimate β(ˆ)1  from Section 2 in hand, we now want to calculate the standard error ofβ(ˆ)1

A. Calculate σ(ˆ)u(2)  (3 points)

Using wage2$residual, calculate the sample variance σ(ˆ)u(2). Use the lecture notes if you need the formula.

Question: How many degrees of freedom did you use in your answer?

B. Calculate SST of exper (2 points)

Calculate the SST of exper

C. Calculate the Std.  Error (3 points)

Using 4A and 4B, calculate the standard error of β(ˆ)1 .

Question: Is the standard error ofβ(ˆ)1  large or small relative to the point estimate ofβ(ˆ)1 ?

D. Calculate the t-statistic (5 points)

Using 4C and your estimate of β(ˆ)1 , calculate the t-statistic

Question:  Since we have a large sample, we can assume a value for tcrit   of 1.96.  Given your answer here, what can you infer about the hypothesis that β1  = 0?

5.  Simple regression

A. Running our regression (10 points)

Let’s run our very first regression - the first of many. I’ll give you the full syntax:

myRegression  <-  lm(Y  ~  X,  data  =  my_data)

What we’re asking R to do here is to regress Y on X. We tell it to use my_data.  The “formula” Y  ~  X says to regress Y onto the right-hand-side variable X, so we are asking for the expected value of Y conditional on X. Now, replace the Y and X in the formula with the names of the variables we’re interested in, and replace my_data with wage2. In the formula, you need only refer to the variable names, and do not need to include wage2$ before them. R will check in the data you give it in the data  = argument for those variable names. The formula format is much easier to use when you have many variables, as we will in the coming weeks, so please use it.

Once we’ve run our regession and saved it as myRegression, we can summarize it using summary():

summary(myRegression)

This will print out our regression output!

Question(2 points): How do the coefficients from 4A compare to the estimates you did “by hand” in Q2? Question(2 points): How does the R2  compare to the R2  you calculated in Q3?

Question(2 points): The output gives the degrees of freedom. How was this calculated?

B. Plotting the Regression (2 points)

Once again, plot the data as in Question 2 with exper on the x-axis and wage on the y-axis.   Add the regression line by adding the following code in the line immediately after your plot:

abline(myRegression,  col  =  ’red’)

No reply, just the plot.

C. Last Question (2 points)

How many hours did you spend on this problem set?

Closing

Remember to knit your work to a PDF to upload to D2L no later than 11:59pm on the due date.