Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set.seed (12345)
- m <- rnorm(20, 0, 1)
- n <- 10
- b1 <- 0.5
- b2 <- 2
- model1_b <- matrix(nrow=n, ncol=2)
- model2_b <- matrix(nrow=n, ncol=2)
- error <- matrix(nrow=20, ncol=n)
- for (a in 1:2){
- for (b in 1:4){
- x <- (m+a)/b
- for (r in 1:10){
- repeat {
- e <- rnorm(20, 0, 0.5) # the error term
- error[,r] <- e
- # OLS estimation of Model_1
- y=b1 + b2*x + e # the true model 1
- Model_1 <- lm (y~x)
- model1_b[r,]=Model_1$coef
- # OLS estimation of Model_2
- y=b1 + b2*(x^2) + e # the true model 2
- Model_2 <- lm (y~x)
- model2_b[r,]=Model_2$coef
- if (Model_1$coef[1]!=0 & Model_2$coef[1]!=0) {break}
- } # end of repeat{} loop
- } # end of for(r){} loop
- } # end of for(b){} loop
- } # end of for(a){} loop
- error
- model1_b
- model2_b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement