HW1 Econ
HW1 Econ
Alexandra Bilbie
2022-10-19
y = beta_true[1] + x * beta_true[2] + e
OLS regression
X<-matrix(c(rep(1,N),x),ncol=2)
## [,1]
## [1,] 5.084425
## [2,] -2.810502
##Plot
plot(x,y)
abline(beta_hat[1],beta_hat[2])
DGP2 - simulation of 20 data points of x and error term, e
Assume x uniform distribution (0,1) Assume error term, e, normal distribution N(0,V)
Assume beta_0=5, beta_1=-2.5
beta_true2<- c(5,-2.5)
N2 = 20
x2 = runif(N2)
V2 = 1
e2 = rnorm(N2,sd=sqrt(V2))
y2 = beta_true2[1] + x2 * beta_true2[2] + e2
OLS regression
X2<-matrix(c(rep(1,N2),x2),ncol=2)
## [,1]
## [1,] 5.992672
## [2,] -4.473001
Plot
plot(x2,y2)
abline(beta_hat2[1],beta_hat2[2])
y3 = beta_true3[1] + x3 * beta_true3[2] + e3
OLS regression
X3<-matrix(c(rep(1,N3),x3),ncol=2)
Plot
plot(x3,y3)
abline(beta_hat3[1],beta_hat3[2])
Run code 10 times and store the values of DGP1 - simulation of 20 data points of
x and error term, e
Assume x uniform distribution (0,1) Assume error term, e, normal distribution N(0,V)
Assume beta_0=5, beta_1=-2.5
beta_true<- c(5,-2.5)
N = 20
V = 0.16
sum1=c(0,0)
B<-matrix(NA,nrow=2, ncol=1)
for (i in 0:9) {
x = runif(20)
e = rnorm(N,sd=sqrt(V))
y = beta_true[1] + x * beta_true[2] + e
X<-matrix(c(rep(1,20),x),ncol=2)
beta_hat<-solve(t(X)%*%X)%*%t(X)%*%y # %*% matrix multiplication
B<-cbind(B, beta_hat) #verifica
sum1=sum1+beta_hat
}
B[,-1]
S<-sum1/10
S
## [,1]
## [1,] 4.938126
## [2,] -2.382396
plot(x,y)
abline(S[1],S[2])
Run code 10 times and store the values of DGP2 - simulation of 20 data points of
x and error term, e
Assume x uniform distribution (0,1) Assume error term, e, normal distribution N(0,V)
Assume beta_0=5, beta_1=-2.5
beta_true<- c(5,-2.5)
N = 20
V = 1
sum2=c(0,0)
B2<-matrix(NA,nrow=2, ncol=1)
for (i in 0:9) {
x = runif(20)
e = rnorm(N,sd=sqrt(V))
y = beta_true[1] + x * beta_true[2] + e
X<-matrix(c(rep(1,20),x),ncol=2)
beta_hat<-solve(t(X)%*%X)%*%t(X)%*%y # %*% matrix multiplication
B2<-cbind(B2, beta_hat) #verifica
sum2=sum2+beta_hat
}
B2[,-1]
S2<-sum2/10
S2
## [,1]
## [1,] 4.870612
## [2,] -2.243231
plot(x,y)
abline(S2[1],S2[2])
Run code 10 times and store the values of DGP2 - simulation of 20 data points of
x and error term, e
Assume x uniform distribution (0,1) Assume error term, e, normal distribution N(0,V)
Assume beta_0=5, beta_1=-2.5
beta_true<- c(5,-2.5)
N = 200
V = 1
sum3=c(0,0)
B3<-matrix(NA,nrow=2, ncol=1)
for (i in 0:9) {
x = runif(200)
e = rnorm(N,sd=sqrt(V))
y = beta_true[1] + x * beta_true[2] + e
X<-matrix(c(rep(1,200),x),ncol=2)
beta_hat<-solve(t(X)%*%X)%*%t(X)%*%y # %*% matrix multiplication
B3<-cbind(B3, beta_hat) #verifica
sum3=sum3+beta_hat
}
B3[,-1]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## [1,] 5.028251 4.930843 5.145483 5.050202 5.200898 4.746231 4.711813
## [2,] -2.519799 -2.482909 -2.781755 -2.766628 -2.855244 -2.151965 -2.130874
## [,8] [,9] [,10]
## [1,] 4.922588 5.200024 4.997076
## [2,] -2.466571 -2.592317 -2.578056
S3<-sum3/10
S3
## [,1]
## [1,] 4.993341
## [2,] -2.532612
plot(x,y)
abline(S3[1],S3[2])
We can see that, the mean of the estimated parameters are close to the true parameter
value regardless of sample size. The variance of the estimated parameters decreases with
larger sample size, i.e. the larger the sample size, the closer will our estimated parameters
be to the true values.