0% found this document useful (0 votes)
17 views8 pages

HW1 Econ

The document simulates univariate OLS regressions with different data generating processes and sample sizes. It runs regressions 10 times each for sample sizes of 20, 20, and 200 observations. It stores the estimated beta coefficients from each iteration and calculates the mean estimated betas across the 10 iterations. The mean estimated betas are close to the true parameter values regardless of sample size. Additionally, increasing the sample size from 20 to 200 observations decreases the variance of the estimated beta coefficients.

Uploaded by

alex97blb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views8 pages

HW1 Econ

The document simulates univariate OLS regressions with different data generating processes and sample sizes. It runs regressions 10 times each for sample sizes of 20, 20, and 200 observations. It stores the estimated beta coefficients from each iteration and calculates the mean estimated betas across the 10 iterations. The mean estimated betas are close to the true parameter values regardless of sample size. Additionally, increasing the sample size from 20 to 200 observations decreases the variance of the estimated beta coefficients.

Uploaded by

alex97blb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

HW1 Econometrics

Alexandra Bilbie

2022-10-19

The univariate OLS regression model


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
x = runif(N)
V = 0.16
e = rnorm(N,sd=sqrt(V))

y = beta_true[1] + x * beta_true[2] + e

OLS regression
X<-matrix(c(rep(1,N),x),ncol=2)

beta_hat<-solve(t(X)%*%X)%*%t(X)%*%y # %*% matrix multiplication


beta_hat

## [,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)

beta_hat2<-solve(t(X2)%*%X2)%*%t(X2)%*%y2 # %*% matrix multiplication


beta_hat2

## [,1]
## [1,] 5.992672
## [2,] -4.473001
Plot
plot(x2,y2)
abline(beta_hat2[1],beta_hat2[2])

DGP3 - simulation of 200 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_true3<- c(5,-2.5)
N3 = 200
x3 = runif(N3)
V3 = 1
e3 = rnorm(N3,sd=sqrt(V3))

y3 = beta_true3[1] + x3 * beta_true3[2] + e3

OLS regression
X3<-matrix(c(rep(1,N3),x3),ncol=2)

beta_hat3<-solve(t(X3)%*%X3)%*%t(X3)%*%y3 # %*% matrix multiplication


beta_hat3
## [,1]
## [1,] 4.887356
## [2,] -2.531579

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]

## [,1] [,2] [,3] [,4] [,5] [,6] [,7]


## [1,] 5.155239 4.709753 4.807696 5.207598 4.839322 5.007667 5.285536
## [2,] -2.766242 -2.159228 -2.247065 -2.985642 -2.344860 -2.402394 -2.746981
## [,8] [,9] [,10]
## [1,] 4.826948 4.655563 4.885933
## [2,] -1.988845 -1.661022 -2.521678

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]

## [,1] [,2] [,3] [,4] [,5] [,6] [,7]


## [1,] 5.105388 4.427309 4.464999 4.351530 5.075414 5.317936 4.936045
## [2,] -3.082967 -1.522304 -1.423048 -1.348495 -2.696321 -3.151011 -2.276611
## [,8] [,9] [,10]
## [1,] 4.844308 4.556676 5.626517
## [2,] -1.650577 -2.201934 -3.079045

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.

You might also like