Hi,
I'm working on a Monte Carlo simulation with an endogenous x, so that I need to do 2SLS in my loop. My purpose is to compare the value and graphs of OLS b1 with 2SLS b1, including the discussion about the effect of sample size on b1.
The pop linear reg is y = 0.5 + x + u. n = 40 or 200. x has correlation with u.
For IV z: x = a0 + 0.1 * z + v. The error terms u and v are distributed as standard normal random variables with a correlation coefficient 0.7 between them.
Right now I'm writing the OLS part and I don't know where I should put IV part and how to show the 0.7 between u and v into the loop. Can anyone help me? Thank you!
My code so far:
clear
set obs 5000
gen sample_id = _n
foreach n in 40 200 {
expand `n'
sort sample_id
gen X = uniform()
gen U = uniform()
gen Y = 0.5 + X + U
gen b1_n_`n' = .
gen se_heter_`n' = .
quietly forvalues i = 1/5000 {
quietly reg Y X if sample_id == `i', robust
replace b1_n_`n' = _b[X] if sample_id == `i'
replace se_heter_`n' = _se[X] if sample_id == `i'
}
duplicates drop sample_id, force
drop X U Y
}
Related Posts with Monte Carlo Simulation with IV 2SLS
Add Trend/Regression line in tslineHello! I have three parameters that measure an examiners performance over time. The data is noted f…
Create local macro already with double quotataion marksDear Statalist I would like to create a local macro for an if-condition that already includes doubl…
Problem with a synth command : error "uno() invalid -- invalid numlist has too many elements"Dear all, As described in the title, I try to implement the Synthetic Control method on STATA to st…
percentage of missing data for each group?Dear All, Suppose that the data set is Code: webuse grunfeld, clear set seed 1234 replace…
Identify 100 biggest companies within a firmyearDear all, We are trying to generate a new dummy variable (biggest_comp_d) indicating whether a comp…
Subscribe to:
Post Comments (Atom)
0 Response to Monte Carlo Simulation with IV 2SLS
Post a Comment