Hi all,
I want to be able to run a Monte Carlo simulation for an econometrics assignment that I have. From what I can tell, I need to design an experiment that has sample sizes of n{10, 100, 1000, 10000]}, each requiring R=1000, where R= replications. For each of the sample sizes, I need to calculate the 25th, 50th, and 75th percentile values. I have some code from stata for this experiment and it listed below. The question I have is how can I create a loop within this program to allow for changing the n number of observations?
clear
local mc = 1000
set seed 368
set obs `mc'
gen data_store_x = .
gen data_store_cons = .
quietly {
forvalues i = 1(1) `mc' {
if floor((`i'-1)/100) == (`i' -1)/100 {
noisily display "Working on `i' out of `mc at $S_TIME'"
}
preserve
clear
set obs = 1000
gen x = rnormal() *3 + 6
gen e = runiform() - 0.5
gen y = 3 + 4*x + e
reg y x, robust
local xcoef = _b[x]
local const = _b[_cons]
restore
replace data_store_x = `xcoef' in `i'
replace data_store_cons = `const' in `i'
}
}
summ data_store_x data_store_cons
0 Response to Monte Carlo Simulation
Post a Comment