[SOLVED] CS计算机代考程序代写 # library we will be using next week

30 $

File Name: CS计算机代考程序代写_#_library_we_will_be_using_next_week.zip
File Size: 621.72 KB

SKU: 3462759973 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


# library we will be using next week
library(tidyverse)

# tidyverse allows us to write code in pipe
x <- 5sqrt(x)x %>% sqrt

# Now we are going to perform a Montecarlo Simulation Exercise
# we want to simulate and estimate the following model
# y = a + b * x + e
# where y and x are variables and e is an error term
# and plot a histogram of estimated beta’s

nobs = 100
a = 2
b = 0.5
nsim = 1000
beta = rep(0, nsim)

for(ii in 1:nsim){
e = rnorm(nobs)
x = rnorm(nobs)
y = a + b * x + e
ols.mod = lm(y ~ x)
beta[ii] = ols.mod$coefficients[2]
}

# we can increase the n. of obs.
# doing so reduces the variability of our estimated beta
# but it doesn’t make it disappear
hist(beta)

# what happens if we introduce correlation between x and e?

for(ii in 1:nsim){
e = rnorm(nobs)
x = rnorm(nobs) + 0.2 * e
y = a + b * x + e
ols.mod = lm(y ~ x)
beta[ii] = ols.mod$coefficients[2]
}

hist(beta)

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS计算机代考程序代写 # library we will be using next week
30 $