We use a data generating process to create a panel data set and now we want to include a lagged variable and see the effect of the bias for different time periods. The data for the first year of the lagged variable for each person is zero, such that $y_it$ only depends on $l.y_it$ after the first period. Thn I want to use the fixed effect estimator in a Monte Carlo simulation with 100 draws. I want to produce a table in which I show the bias of the estimate, and show how it depends on the number of time periods for each individual and on the true value of the coefficient on the lagged value $l.y_it$. I want to do this for 5, 10, 20 and 50 time periods for the true value of the coefficient being 0.5.
This is the code I already wrote in Stata. The bias we get is way too big (1.43) and the bias is exactly the same for all 4 different time periods. Moreover, when I display the results I get $_sim_1$ and $_sim_4$ as variables instead of $_b_l.y_it$ and $_se_l.y_it$; how do I change this?
This is the code I already wrote in Stata. The bias we get is way too big (1.43) and the bias is exactly the same for all 4 different time periods. Moreover, when I display the results I get $_sim_1$ and $_sim_4$ as variables instead of $_b_l.y_it$ and $_se_l.y_it$; how do I change this?
Code:
clear all set seed 345398 capture program drop mcprog program mcprog clear set seed 345398 drawnorm alpha_i, n(200) gen persnr = _n expand 5 bysort persnr: g year = _n drawnorm nu_it e_it, n(1000) g x_it=nu_it+alpha_i drop nu_it g y_it=3+alpha_i+2*x_it+e_it xtset persnr year replace y_it = 3+alpha_i+2*x_it+e_it + 0.5*l.y_it if year > 1 xtreg y_it l.y_it x_it , fe end simulate _b _se, reps(100): mcprog sum local time_periods 5 10 20 50 * Create an empty matrix to store bias results matrix results = J(4, 1, .) * Loop through different time periods local row = 1 foreach t in `time_periods' { clear simulate _b _se, reps(100): mcprog return list * Store the estimated coefficient for l_y_it in a local macro local estimated_coefficient = _b[x_it] * Calculate bias as the difference between the estimated and true coefficient local bias = `estimated_coefficient' - 0.5 * Store bias in the results matrix matrix results[`row', 1] = `bias' * Increment row index local row = `row' + 1 } * Display the results in a table matlist results, format(%9.6f)
Comment