------------------------------------------------------------------------------------------------------------------------------- name: log: c:\Imbook\courses\2013_bgpe_germany\day1olsgls\ct_asymptotic.txt log type: text opened on: 23 May 2013, 14:32:02 . . * STATA Program . * For A. Colin Cameron and Pravin Trivedi "Lectures in Microeconometrics" . * Asymptotic Theory - LLN and CLT . . * Requires no dataset . . ********** SETUP ********** . . set more off . version 12.0 . set mem 10m set memory ignored. Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically. . set scheme s1mono /* Graphics scheme */ . . ******* ASYMPTOTIC THEORY - LLN and CLT in IID CASE . . * Draw from uniform with population mean 0.5 . * Demonstrate LLN by finding average for a very large sample . * Demonstrate CLT by simulating to obtain many averages . . * Small sample: sample mean differs from population mean . quietly set obs 30 . set seed 10101 . quietly generate x = runiform() . mean x Mean estimation Number of obs = 30 -------------------------------------------------------------- | Mean Std. Err. [95% Conf. Interval] -------------+------------------------------------------------ x | .5459987 .0511899 .4413036 .6506939 -------------------------------------------------------------- . . * Consistency: Large sample: sample mean is very close to population mean . clear all . quietly set obs 100000 . set seed 10101 . quietly generate x = runiform() . mean x Mean estimation Number of obs = 100000 -------------------------------------------------------------- | Mean Std. Err. [95% Conf. Interval] -------------+------------------------------------------------ x | .4988239 .0009133 .4970339 .5006138 -------------------------------------------------------------- . . * Central limit theorem . * Write program to obtain sample mean for one sample of size numobs (= 30) . program onesample, rclass 1. args numobs 2. drop _all 3. quietly set obs `numobs' 4. generate x = runiform() 5. summarize x 6. return scalar meanforonesample = r(mean) 7. end . * Run this program 10,000 times to get 10,000 sample means . quietly simulate xbar = r(meanforonesample), seed(10101) reps(10000) nodots: /// > onesample 30 . * Summarize the 10,000 sample means . summarize xbar Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- xbar | 10000 .4995835 .0533809 .3008736 .6990562 . . * Draw histogram and kernel density estimate for z=(xbar-mu)/(sigma/sqrt(N)) . generate z = (xbar-0.500) / (sqrt(1/12)/sqrt(30)) . quietly histogram z, normal xtitle("z from many samples") . * graph export ct_asymptoticclt.wmf, replace . . ********** CLOSE OUTPUT . * log close . * clear . * exit . . . end of do-file . exit, clear