-----------------------------------------------------------------------------------
log: /Users/baum/doc/Courses 2005-2006/EC77101/771simul2_9.smcl
log type: smcl
opened on: 22 Jan 2007, 10:40:02
.
. * EC771: univariate simulation experiment 2 cfb 4113 rev 4123
. * rev for 9.1 syntax 6317
.
. set more off
. local reps 1000
. global true_mu 50
.
. * set up model: y1 contains a homoskedastic error
. * y2 contains an error term which is heteroskedastic across regions
.
.
. * define the simulation experiment
. capture program drop mcsimul2
. program define mcsimul2, rclass
1. version 9.1
2. syntax [, c(real 1)]
3. tempvar e1 e2
4.
. gen `e1' = invnorm(uniform())*`c'*zmu
5. gen `e2' = invnorm(uniform())*`c'*z_factor
6. replace y1 = true_y + `e1'
7. replace y2 = true_y + `e2'
8. ttest y1 = 0
9. return scalar p1 = r(p)
10. ttest y2 = 0
11. return scalar p2 = r(p)
12. return scalar c = `c'
13. end
.
. forv i=1/10 {
2. * 50 states' data from US Census
. qui webuse census2, clear
3. * true_y indicates the variable being used as base for the noisy measurement
. gen true_y = $true_mu
4. * z_factor is the variable generating heteroskedasticity in e2
. gen z_factor = region
5. sum z_factor, meanonly
6. scalar zmu = r(mean)
7. qui {
8. gen y1 = .
9. gen y2 = .
10. local c = `i'*10
11. simulate c=r(c) p1=r(p1) p2=r(p2), ///
> saving(ccc`i',replace) nodots reps(`reps'): mcsimul2, c(`
> c')
12. }
13. }
.
. * combine the results files into a single file for tabulation
. use ccc1
(simulate: mcsimul2)
. forv i=2/10 {
2. append using ccc`i'
3. }
. gen RfNull_1 = (1-p1)*100
. gen RfNull_2 = (1-p2)*100
. gen R5pc_1 = (p1<0.05)/10
. gen R5pc_2 = (p2<0.05)/10
. format %6.2f R5pc_1
. format %6.2f R5pc_2
. save ccc_1_10,replace
(note: file ccc_1_10.dta not found)
file ccc_1_10.dta saved
. * get descriptives on results file
. tabstat p1 p2 RfNull_1 RfNull_2,stat(mean) by(c)
Summary statistics: mean
by categories of: c (r(c))
c | p1 p2 RfNull_1 RfNull_2
---------+----------------------------------------
10 | 8.25e-15 6.25e-12 100 100
20 | 5.29e-06 .0000439 99.99947 99.99561
30 | .0025351 .0065619 99.74649 99.34381
40 | .0222498 .0275325 97.77502 97.24675
50 | .0598702 .069537 94.01298 93.0463
60 | .1026593 .1214913 89.73407 87.85087
70 | .1594983 .1962834 84.05017 80.37166
80 | .2173143 .2267421 78.26857 77.32579
90 | .2594667 .274362 74.05333 72.5638
100 | .2898857 .3163445 71.01143 68.36555
---------+----------------------------------------
Total | .1113485 .1238899 88.86515 87.61101
--------------------------------------------------
. tabstat R5pc_1 R5pc_2,stat(sum) by(c) nototal
Summary statistics: sum
by categories of: c (r(c))
c | R5pc_1 R5pc_2
---------+--------------------
10 | 100 100
20 | 100 100
30 | 99.1 97.4
40 | 90.6 85.3
50 | 74.8 72.1
60 | 59.5 55.1
70 | 45.4 42.4
80 | 39.8 34.9
90 | 29.5 28.4
100 | 27.7 22.8
------------------------------
.
. set more on
. log close
log: /Users/baum/doc/Courses 2005-2006/EC77101/771simul2_9.smcl
log type: smcl
closed on: 22 Jan 2007, 10:43:00
-----------------------------------------------------------------------------------