-----------------------------------------------------------------------------------
       log:  /Users/baum/doc/Courses 2005-2006/EC77101/771simul1_9.smcl
  log type:  smcl
 opened on:  22 Jan 2007, 10:15:57


. . * EC771: univariate simulation experiment cfb 4113 . * updated for 9.1 syntax 6317 . . set more off

. local reps 1000

. . * 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 mcsimul1

. program define mcsimul1, rclass 1. version 9.1 2. syntax [, c(real 1)] 3. tempvar e1 e2 4. . gen double `e1' = invnorm(uniform())*`c'*zmu 5. gen double `e2' = invnorm(uniform())*`c'*z_factor 6. replace y1 = true_y + `e1' 7. replace y2 = true_y + `e2' 8. summ y1 9. return scalar mu1 = r(mean) 10. return scalar se_mu1 = r(sd)/sqrt(r(N)) 11. summ y2 12. return scalar mu2 = r(mean) 13. return scalar se_mu2 = r(sd)/sqrt(r(N)) 14. return scalar c = `c' 15. 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 = age 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) mu1=r(mu1) se_mu1=r(se_mu1) mu2=r(mu2) > se_mu2=r(se_mu2), /// > saving(c`i',replace) nodots reps(`reps'): mcsimul1, c(`c' > ) 12. } 13. }

. . * combine the results files into a single file for tabulation . use c1 (simulate: mcsimul1)

. forv i=2/10 { 2. append using c`i' 3. }

. gen het_infl = se_mu2 / se_mu1

. save c_1_10,replace file c_1_10.dta saved

. . * get descriptives on results file . tabstat mu1 se_mu1 mu2 se_mu2 het_infl, stat(mean) by(c)

Summary statistics: mean by categories of: c (r(c))

c | mu1 se_mu1 mu2 se_mu2 het_infl ---------+-------------------------------------------------- .1000000 | 29.49857 .250647 29.50047 .2511254 1.002349 .2000000 | 29.49789 .2588248 29.4971 .2602214 1.007029 .3000000 | 29.50245 .2716779 29.49867 .2758834 1.018764 .4000000 | 29.51036 .2898002 29.50224 .2945657 1.021542 .5 | 29.50816 .3100689 29.50049 .3202264 1.039481 .6000000 | 29.50354 .334258 29.50189 .3459702 1.043277 .6999999 | 29.49899 .3604802 29.49549 .3721055 1.04044 .8000000 | 29.49933 .3876827 29.48983 .4066115 1.057522 .8999999 | 29.51431 .4181407 29.50231 .4337589 1.047648 1 | 29.49386 .4477914 29.48953 .4715086 1.063031 ---------+-------------------------------------------------- Total | 29.50275 .3329372 29.4978 .3431977 1.034108 ------------------------------------------------------------

. tabstat het_infl, stat(mean q ) by(c)

Summary for variables: het_infl by categories of: c (r(c))

c | mean p25 p50 p75 ---------+---------------------------------------- .1000000 | 1.002349 .9801603 1.001544 1.023048 .2000000 | 1.007029 .9631492 1.006886 1.047167 .3000000 | 1.018764 .9556518 1.015823 1.070618 .4000000 | 1.021542 .9427943 1.015947 1.092599 .5 | 1.039481 .9546044 1.03039 1.114773 .6000000 | 1.043277 .944645 1.03826 1.130782 .6999999 | 1.04044 .9386177 1.035751 1.126928 .8000000 | 1.057522 .9555817 1.050923 1.156035 .8999999 | 1.047648 .9436705 1.038448 1.140402 1 | 1.063031 .9514042 1.048108 1.159396 ---------+---------------------------------------- Total | 1.034108 .9575833 1.020554 1.098434 --------------------------------------------------

. . set more on

. log close log: /Users/baum/doc/Courses 2005-2006/EC77101/771simul1_9.smcl log type: smcl closed on: 22 Jan 2007, 10:16:10 -----------------------------------------------------------------------------------