Dear Statalist-ers,
I would like to perform a Monte Carlo simulation in Stata, but I get some counter-intuitive results, and I was wondering if someone could kindly check that my code is doing what I would like it do to.
I am simulating a panel dataset with individual unobserved effects, a lagged dependent variable, lagged feedback effects, and a linear time trend. This is the DGP that I assume:

I am interested in simulating the behaviour of the OLS estimator of the coefficient on X(it-1) in the first equation, the true value of which is -0.2.
I set T= 10 and N=182 (panel units), for a total of 1820 observations. I produce 2000 repeated samples (replications) of this size, each time running a FE regression for the first equation and storing the estimated coefficient on X(it-1). Then I compute the expectation of the OLS estimates obtained in this way.
This is the code I use:
Is this code actually implementing the DGP as per above?
Thanks a lot!
Luca
I would like to perform a Monte Carlo simulation in Stata, but I get some counter-intuitive results, and I was wondering if someone could kindly check that my code is doing what I would like it do to.
I am simulating a panel dataset with individual unobserved effects, a lagged dependent variable, lagged feedback effects, and a linear time trend. This is the DGP that I assume:
I am interested in simulating the behaviour of the OLS estimator of the coefficient on X(it-1) in the first equation, the true value of which is -0.2.
I set T= 10 and N=182 (panel units), for a total of 1820 observations. I produce 2000 repeated samples (replications) of this size, each time running a FE regression for the first equation and storing the estimated coefficient on X(it-1). Then I compute the expectation of the OLS estimates obtained in this way.
This is the code I use:
Code:
program drop _all program define ar1sim, rclass drop _all set obs 1820 gen id = round(uniform()*182) sort id by id: gen t = _n xtset id t gen u = invnorm(uniform()) gen v = invnorm(uniform()) gen y = invnorm(uniform()) gen x = invnorm(uniform()) more by id: replace y = y - 0.05*t + 0.01*id + u if t==1 by id: replace x = x + 0.04*t + 0.02*id + v if t==1 forvalues i = 2/10 { by id: replace y = 0.9*L.y - 0.2*L.x - 0.05*t + 0.01*id + u if t==`i' by id: replace x = 0.5*L.x - 0.2*L.y + 0.04*t + 0.02*id + v if t==`i' } more xtreg y L.y L.x t, fe more return scalar b = _b[L.ln_y] more end more simulate beta = r(b), reps(2000): ar1sim program drop _all sum beta
Is this code actually implementing the DGP as per above?
Thanks a lot!
Luca
Comment