In this video, we will learn how to perform the Monte Carlo Simulation together. Monte Carlo simulation repeats the data generating process and estimations hundreds or thousands of times. It is a great way to learn, understand, and evaluate estimation methods. Let me show you the performance of OLS and IV estimation methods in the presence of endogenous explanatory variables.
#MonteCarloSimulation #simulate #DataGeneratingProcess
*****************************
*53. Monte Carlo Simulation *
*****************************
clear
program drop _all
cd "/Users/bobwen/Documents/2022 Youtube Teaching/Introductory Stata/53. Simulation2/"
capture log close
log using simulation2.log, text replace
*Endogenous x2 variable: OLS
*write a program
program define simu1
clear
set obs 5000
generate e1=rnormal()
generate x1=rnormal()
generate x2=rnormal()+e1
generate y=1+1*x1+1*x2+e1
regress y x1 x2
end
*execute the program
simu1
simulate, rep(100) seed(8964): simu1
summarize
*Endogenous x2 variable: IV
program define simu2
clear
set obs 5000
generate e1=rnormal()
generate z=rnormal()
generate x1=rnormal()
generate x2=rnormal()+e1+z
generate y=1+1*x1+1*x2+e1
eregress y x1, endogenous(x2=z x1)
end
simu2
simulate, rep(100) seed(8964): simu2
summarize
log close