﻿ ECON1代写 Assignment代写 Stata代写 Python代写 C ++代写

# ECON1代写 Assignment代写 Stata代写 Python代写 C ++代写

2021-02-28 13:29 星期日 所属： 作业代写 浏览：50

## ECON 4403

ECON1代写 It’s due on February 5 by email (by midnight). You can submit it individually or as a team (maximum 3 members). Sections C is optional.

Winter 2019

### Assignment 2 ECON1代写

It’s due on February 5 by email (by midnight). You can submit it individually or as a team (maximum 3 mebers). Sections C is optional. If you choose to answers it, you’ll get some bonus points. Remember: the true reward will not be the mark you receive from these assignments, but it will be what you learn.

• You can use R, Stata, Stata – Mata, Python, C++, or
• What you submit must be your own
• Pay attention to our format restrictions as stated in A1. I need ONLY rmd, smcl or sources code ﬁles, nothingelse!
• The solutions will be provided later only for R, Stata, andC++.ECON1代写

This assignment has 3 parts:

1. Deﬁninga data generating model (DGM).
2. OLSwith linear algebra using one
3. MonteCarlo simulations: sampling distributions with multiple  (BONUS) Sources: See A1 and read the textbook. There are multiple sections in the book about MC simulations.

### Background ECON1代写

In this exercise we will create our own sampling distribution for the OLS estimators. Re- member, since these estimators are linear functions of y (L in BLUE), they themselves are random variables too. Hence each of them has a sampling distribution. The population y is a product of a data generating model that is deﬁned by a systematic part (model that contains beta’s and x’s) and an unknown stochastic part (error) that follows a Gaussian distribution (that is i.i.d, for now). We will generate 5000 samples by this DGM. Each sample will have 500 observations. Thus, we will calculate 5000 beta_hat vectors.

The objective is to see the distribution on these 5000 OLS estimators, or more speciﬁcally whether beta_hat is BLUE of beta. But before that we have to decide whether x’s are stochastic or not. In this assignment, we will assume that x’s are ﬁxed in repeated samples.ECON1代写 So, if we have 5000 samples with 500 observations, we will have the same set of x’s in each sample. We will not see in this assignment how we relax this assumption and make x’s random changing sample to sample.

### A. Data GeneratingModel

1. Createa vector of 1000 1’s and assign it to x1.
2. Create a vector with 1000 random integers between 0 and 20 and assign it to x2.
3. Createa vector with 1000 random 0s and 1s and assign it to x3.
4. Createa vector with 1000 random numbers drawn from a normal distribution (mean = 2, sd = 1.25) and assign it to x5.
5. Create a coeﬃcient vector with your choice of For example, beta = (12,-0.7, 34, -0.17, 5.4).ECON1代写

6.For the following DGM, you need to have a vector of 1000 random “errors” drawn from a “Gaussian” distribution (Call it u ~ N(0,1)).

1. Theabove model is y Xbeta u, where X is a 1000 x 5 matrix with 5 x’s. So don’t forget to create X!
2. Congratulations! You have deﬁned your ﬁrst DGM. This DGM will create our population in Section

### B.OLS with linear algebra with one sample:

For  the following operations, you need to create only one sample with 50 observations randomly selected from 1000 observations you generated in (A). In R, to sample 50 observations from x5, for ex- ample, the following code would be enough: sample(x5, 50, replace=TRUE). Notice that you have 2 separate “containers” to sample from: y and X. If you samplesepa- rately, this would create 2 diﬀerent orders of  Therefore, you have to put y and X together and then sample 50 observations. This can be done in R by using cbind for y and X to create a new matrix. Here is my code for this operation:

X <- cbind(x1, x2, x3, x2x3, x5) beta <- c(12, -0.7, 34, -0.17, 5.4)

y <- X%*%beta + u data <- cbind(y, X) ECON1代写

samp <- data[sample(nrow(data), 50, replace = TRUE), ] Xs <- cbind(samp[ ,2:6])

ys <- samp[ ,1]

b <- solve(t(Xs)%*%Xs)%*%t(Xs)%*%ys

1. Now you have X (50×5) and y (50×1). You’ll ﬁnd the estimators of beta.But

ﬁrst, is this problem solvable? Apply the rank-test.ECON1代写

1. Findvector beta_hat (estimators of beta) that deﬁnes the SRF.How close are they to the true population parameters (beta)?
2. Find yi and ui and assign them to yhat and uhat.

4.Prove the following properties of OLS estimators.

a.E[E(y|x] =E(y)

b.E(X′uhat ) = 0

c.E(yhat′ uhat) = 0

5.Find the variance-covariance matrix (VCM) for uhat and assign it to VCM_uhat. What’s trace[VCM_uhat]/(n-k)?

1. Does it look like VCM_uhat @ /span>2I푛? Inspect it for its first 10×10. We will talk about it more in the next section.ECON1代写
2. Find P (projection matrix) and M (annihilator matrix). Show that PX ºX, MM

º M, MX º 0, and trace[M] = n – k.

1. Find VCM for beta_hat and assign it to VCM_betahat. Create a vector of es- timator variances and assign itto var_betahat.
4. Calculate F-value.

### C. MonteCarloSimulationsforsamplingdistributions ECON1代写

We will create 5000 samples with our DGM deﬁned in (A). Each of these samples will have 500 observations. There are multiple ways to do that. In this assignment we have ﬁxed (non-stochastic) x’s. Therefore, we will create x’s out of the loop to ﬁx their val- ues for repeated samples and then we use DGM to create y’s within a loop for each sample. Here I show you how this can be done with a simple one-variable example for Stata with beta1 = 2.1 and beat2 = -0.7:

clear

set obs 5000

quietly generate x1 = 1 in 1/500 set seed 123

quietly generate x2 = runiform() in 1/500 gen b2bar =.ECON1代写

gen seb2 =.

forvalues i=1/5000 {

quietly generate err = rnormal() in 1/500 quietly generate y = 2.1*x1 – 0.7*x2 + err quietly reg y x2

quietly replace b2bar = _b[x2] in `i’ quietly replace seb2 = _se[x2] in `i’

quietly drop err y

}

drop if b2bar ==. drop if seb2 ==. sum b2bar

sum seb2

#### Here are the steps/questions for this section:

1. Create 5000 samples (with 500 observations) with your DGM and make sure that your x’s are identical in each of 5000 samples. You will have ﬁve sampling distri- butions each of which is for one estimator in beta_hat. Visually check the distri- butionof at least for one estimator to see whether it looks like having a normal dis-tribution. Calculate the mean of each of these sampling distributions. ComparetCompare them with the population parameters.   Are they similar as we expect? That is if E(β)= β?ECON1代写
1. Thecentral limit theorem tells us that if the sample size is large enough, the sam-

distribution. Change u~ N(0,1) to ~ uniform(0,1) in your DGM. Repeat the pling distribution will be normal, even if the error term doesn’t follow a Gaussian same process in (1) and see if your sampling distribution is still normal with unbi- ased estimators.

1. Now we are going to look at the variances of our estimators. The estimatorvari-ances measure the sampling variation in estimates. Remember,with our i.i.d. assumptions. Yet, we don’t need these assumptions in this case because we created the data with the Gaussian disturbances.
##### This is a (kx k) matrix and each element on the diagonal is the “true” variance of one estima-tor given in beta_hat.

a.Find the “true” variances of each estimator: var(β)δ=(X’X)ECON1代写

b.Remember the elements on the diagonal of each uu′ ) are . And we assume that they are equal. How can we calculate them in our simulation and how can we test, for example, if In this step,we answer these questions. First, we will bind VCM_uhat derived from each sampleThis will give us 500 x 5000 matrix.

Thus, each column in this matrix will have 500 u’sfrom each sample.Hence, the fifirst row of this matrix will contain 5000 u1’s. Similarly, the last row will have 5000 u >500’s.Now, we can calculate and see if from each row. In fact, we can also check if /span>푖/span>푗) ≅ 0. Please calculate a couple of variances and covariances and see if these conditions are satisfified. Remember these are called no-autocorrelation and homoscedasticity conditions, a.k.a. i.i.d. errors.ECON1代写

c.Comment on if /span>2) ≅ /span>2 and check if б

We will relax some of the Gauss-Markov assumptions in the following assignments. We will see how the cases of multicollinearity, autocorrelation, heteroscedasticity, measurement errors, and model misspecififications would affffect these “naïve” results (that is SRF is BLUE of PRF) presented in this assignment. Therefore, you should have a concrete understanding in every step here in order to do well in A3 and A4.ECON1代写

Hint: u ~ 0,1) is a standard uniform distribution and 0 and 1 are not the mean and the variance of the distribution but the minimum and maximum numbers in the distribution. What’s E(u) and var(u) then? What happens if ≠ 0, but a constant? Remember it from ECON 3303.