You are on page 1of 4

(a) In Stata, set up observations for n=60, then, generate x1i = 100 +i and x2i = 1 +vi

for i = 1, ..., 60 and vi ~N(0,1), and y1i = 10 + 2x1i + 10x2i + u1i where u1i ~N(0,10).
(b) Generate y2i = 10 + 2x1i + 10x2i + u2i where u2i = 10x2i + εi and εi ~N(0,10).
(c) Estimate model (1) y1i = β0 + β1x1i + β2x2i + u1i, and
model (2) y2i = α0 + α 1x1i + α2x2i + u2i
. *(a)–(c)
. set obs 60
number of observations (_N) was 0, now 60
. g i=_n
. g x1=100+i
. g v=rnormal(0,1)
. g x2=1+v
. g u1=rnormal(0,10)
. g y1=10+2*x1+10*x2+u1
. reg y1 x1 x2
Source | SS df MS Number of obs = 60
-------------+---------------------------------- F(2, 57) = 416.29
Model | 80950.7741 2 40475.3871 Prob > F = 0.0000
Residual | 5542.10603 57 97.2299303 R-squared = 0.9359
-------------+---------------------------------- Adj R-squared = 0.9337
Total | 86492.8802 59 1465.98102 Root MSE = 9.8605
------------------------------------------------------------------------------
y1 | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
x1 | 2.084901 .0735614 28.34 0.000 1.937597 2.232206
x2 | 8.269324 1.271166 6.51 0.000 5.723859 10.81479
_cons | -1.208322 9.801039 -0.12 0.902 -20.83456 18.41792
------------------------------------------------------------------------------
. est store y1
. g u2=10*x2+rnormal(0,10)
. g y2=10+2*x1+10*x2+u2
. reg y2 x1 x2
Source | SS df MS Number of obs = 60
-------------+---------------------------------- F(2, 57) = 715.77
Model | 86052.0712 2 43026.0356 Prob > F = 0.0000
Residual | 3426.36327 57 60.1116364 R-squared = 0.9617
-------------+---------------------------------- Adj R-squared = 0.9604
Total | 89478.4345 59 1516.58364 Root MSE = 7.7532
------------------------------------------------------------------------------
y2 | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
x1 | 1.943463 .0578402 33.60 0.000 1.82764 2.059286
x2 | 18.67282 .9994969 18.68 0.000 16.67136 20.67428
_cons | 19.01907 7.706397 2.47 0.017 3.587277 34.45087
------------------------------------------------------------------------------
. est store y2
. save "D:\Master program\Econometrics\Workshop&Assign\workshop3-6604040086.dta"
file D:\Master program\Econometrics\Workshop&Assign\workshop3-6604040086.dta saved
. *(d)
. tabstat x1 x2, f(%9.3f) stat(N mean med sd min max)
stats | x1 x2
---------+--------------------
N | 60.000 60.000
mean | 130.500 1.059
p50 | 130.500 1.071
sd | 17.464 0.980
min | 101.000 -1.661
max | 160.000 3.564
------------------------------
. tabstat u1 u2, f(%9.3f) stat(N mean med sd min max)
stats | u1 u2
---------+--------------------
N | 60.000 60.000
mean | -0.606 10.314
p50 | -1.052 10.417
sd | 9.480 14.390
min | -19.722 -16.031
max | 23.844 39.758
------------------------------
.
. *(e)
. est table y1 y2, star(.1 .05 .01) stat(N rss rmse F r2 r2_a)

----------------------------------------------
Variable | y1 y2
-------------+--------------------------------
x1 | 1.8725569*** 2.0361691***
x2 | 10.636255*** 20.131579***
_cons | 25.351784*** 4.8619038
-------------+--------------------------------
N | 60 60
rss | 4985.6248 6383.8797
rmse | 9.3523848 10.582906
F | 394.86613 431.62242
r2 | .93268238 .93805996
r2_a | .93032036 .93588663
----------------------------------------------
legend: * p<.1; ** p<.05; *** p<.01
(d) What are the differences between x1i and x2i and between u1i and u2i.
Answer: The difference between x1 and x2 is x1 is gotten by generating fixed numbers but x2 is
gotten by generating random numbers. from the table [tabstat x1 x2, f(%9.3f) stat(N mean med
sd min max)] x1 is normal distribution because mean and median are equal more than in x2.
The difference between u1 and u2 is u2 has endogeneity problem because u2 is generate
from x2.
(e) Make comparison of the estimated results of model (1) and (2).
Answer: model (1) is more preferable than model(2) because coefficient of variables in model
(1) are more closely with the model that we are setted than model(2). That mean model (2) are
more biased than in model (1).

(f) Repeat steps (a) to (d) for 100 times. Confirm whether the estimated coefficients
from OLS are unbiased using one-sample t-test. Why does the estimated results of
y2i provide a biased estimated result for α2?
Answer: from t test in MC2 (ttest _b_x2==10)
that set hypothesis,H0: _b_x2=10, Ha: _b_x2 ≠ 10, In t test, Pr(|T| > |t|) = 0.0000.
So, we are reject null hypothesis that mean _b_x2(α2) is not equal to 10 and it is biased.

. *(f) Command to Generate True Data


. clear all
. set obs 60
number of observations (_N) was 0, now 60
. g i=_n
. g x1=100+i
. g v=rnormal(0,1)
. g x2=1+v
. g true_y=10+2*x1+10*x2
. save "D:\Master program\Econometrics\Workshop&Assign\workshop3-6604040086.dta", replace
file D:\Master program\Econometrics\Workshop&Assign\workshop3-6604040086.dta saved

. *Command to perform Monte Carlo Simulation for y1


. program MC1
1. use "D:\Master program\Econometrics\Workshop&Assign\workshop3-6604040086.dta", clear
2. g y1=true_y + rnormal(0,10)
3. reg y1 x1 x2
4. end
. *Command to perform Monte Carlo Simulation for y2
. program MC2
1. use "D:\Master program\Econometrics\Workshop&Assign\workshop3-6604040086.dta", clear
2. g y2=true_y + (10*x2+rnormal(0,10))
3. reg y2 x1 x2
4. end
.
. simulate _b _se, reps(100): MC1
command: MC1
Simulations (100)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.................................................. 50
.................................................. 100
. mean _b_x1 _b_x2 _b_cons
Mean estimation Number of obs = 100
--------------------------------------------------------------
| Mean Std. Err. [95% Conf. Interval]
-------------+------------------------------------------------
_b_x1 | 2.013271 .0074924 1.998405 2.028138
_b_x2 | 10.05326 .0943673 9.866018 10.24051
_b_cons | 8.162883 .9910818 6.196361 10.1294
--------------------------------------------------------------

. ttest _b_x1==2
One-sample t test
------------------------------------------------------------------------------
Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
---------+--------------------------------------------------------------------
_b_x1 | 100 2.013271 .0074924 .0749244 1.998405 2.028138
------------------------------------------------------------------------------
mean = mean(_b_x1) t = 1.7713
Ho: mean = 2 degrees of freedom = 99

Ha: mean < 2 Ha: mean != 2 Ha: mean > 2


Pr(T < t) = 0.9602 Pr(|T| > |t|) = 0.0796 Pr(T > t) = 0.0398

. ttest _b_x2==10
One-sample t test
------------------------------------------------------------------------------
Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
---------+--------------------------------------------------------------------
_b_x2 | 100 10.05326 .0943673 .9436735 9.866018 10.24051
------------------------------------------------------------------------------
mean = mean(_b_x2) t = 0.5644
Ho: mean = 10 degrees of freedom = 99
Ha: mean < 10 Ha: mean != 10 Ha: mean > 10
Pr(T < t) = 0.7131 Pr(|T| > |t|) = 0.5737 Pr(T > t) = 0.2869

. ttest _b_cons==10
One-sample t test
------------------------------------------------------------------------------
Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
---------+--------------------------------------------------------------------
_b_cons | 100 8.162883 .9910818 9.910818 6.196361 10.1294
------------------------------------------------------------------------------
mean = mean(_b_cons) t = -1.8536
Ho: mean = 10 degrees of freedom = 99
Ha: mean < 10 Ha: mean != 10 Ha: mean > 10
Pr(T < t) = 0.0334 Pr(|T| > |t|) = 0.0668 Pr(T > t) = 0.9666

. simulate _b _se, reps(100): MC2


command: MC2
Simulations (100)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.................................................. 50
.................................................. 100
. mean _b_x1 _b_x2 _b_cons
Mean estimation Number of obs = 100
--------------------------------------------------------------
| Mean Std. Err. [95% Conf. Interval]
-------------+------------------------------------------------
_b_x1 | 2.008807 .0074507 1.994023 2.023591
_b_x2 | 19.93914 .1053086 19.73019 20.1481
_b_cons | 9.082396 .9551518 7.187168 10.97762
--------------------------------------------------------------
. ttest _b_x1==2
One-sample t test
------------------------------------------------------------------------------
Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
---------+--------------------------------------------------------------------
_b_x1 | 100 2.008807 .0074507 .0745066 1.994023 2.023591
------------------------------------------------------------------------------
mean = mean(_b_x1) t = 1.1820
Ho: mean = 2 degrees of freedom = 99
Ha: mean < 2 Ha: mean != 2 Ha: mean > 2
Pr(T < t) = 0.8800 Pr(|T| > |t|) = 0.2400 Pr(T > t) = 0.1200

. ttest _b_x2==10
One-sample t test
------------------------------------------------------------------------------
Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
---------+--------------------------------------------------------------------
_b_x2 | 100 19.93914 .1053086 1.053086 19.73019 20.1481
------------------------------------------------------------------------------
mean = mean(_b_x2) t = 94.3811
Ho: mean = 10 degrees of freedom = 99

Ha: mean < 10 Ha: mean != 10 Ha: mean > 10


Pr(T < t) = 1.0000 Pr(|T| > |t|) = 0.0000 Pr(T > t) = 0.0000

. ttest _b_cons==10
One-sample t test
------------------------------------------------------------------------------
Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
---------+--------------------------------------------------------------------
_b_cons | 100 9.082396 .9551518 9.551518 7.187168 10.97762
------------------------------------------------------------------------------
mean = mean(_b_cons) t = -0.9607
Ho: mean = 10 degrees of freedom = 99
Ha: mean < 10 Ha: mean != 10 Ha: mean > 10
Pr(T < t) = 0.1695 Pr(|T| > |t|) = 0.3390 Pr(T > t) = 0.8305

.
end of do-file

You might also like