Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab 8 Objectives: Using simulation methods to demonstrate coverage properties of

ID: 3159280 • Letter: L

Question

Lab 8

Objectives:

Using simulation methods to demonstrate coverage properties of confidence intervals.

Using Stata to calculate confidence intervals and perform t-tests.

Calculate area in upper tail and percentiles of the t distribution

Procedures:

Using simulation methods to demonstrate coverage properties of confidence intervals.

When you calculate a confidence interval (CI), you interpret it according to its long term coverage frequency: a 95% CI should cover its target parameter about 95% of the time. Today you will demonstrate this for an N (10, 4) distribution. You will calculate CI’s assuming ? is known (in this case ? = 4) so you use values from the normal table for the CI. You will simulate 100 samples of size 10 from this population and calculate CI’s for each sample. Then you will plot the samples using Stata.

Set obs 1000. This is total number of observations for 100 samples of size 10 each:

     set obs 1000

Now create a variable to distinguish your samples:

gen sample=int((_n-1)/10)+1

sort sample

Simulate your normal data:

     set seed 19981101

gen x=rnormal(10,4)

Calculate sample mean for each sample:

by sample: gen xbar=sum(x)/_n

Since you only need the sample averages, drop all but the last observation in each sample:

by sample: drop if _n < _N

Calculate the upper and lower bound for the 95% CIs of the 100 samples

gen ciupper = xbar + 1.96*4/sqrt(10)

gen cilower = xbar - 1.96*4/sqrt(10)

Calculate how many of your intervals actually covered the target mean µ=10:

gen cover = (cilower<10)&(ciupper>10)

tab cover

Graph your CI’s:

twoway (rcap ciupper cilower sample, sort), yline(10)

Using Stata to calculate confidence intervals and perform t-tests.

Click “File” -> “Open” -> Choose “Descriptive_gss.dta” from your computer

We are going to test if the mean age of this sample equals to 46 or not (H0: µ = 46; HA: µ ? 46)

by using the following command:

ttest age=46

In the output, you will also get the 95% confidence intervals of age based on t-distribution.

To calculate the 90% confidence intervals of mean age by gender, we need to use the follow commands:

sort sex

by sex: ttest age=46, level(90)

Exercise:

A. Use t-test to test if www hours per week (wwwhr) is significantly different from 6.

B. Repeat the same test by gender.

Calculate area in upper tail and percentiles of the t distribution

P( t38 > 1.95 ):

display ttail(38, 1.95)

To obtain the 97.5th percentile of a t distribution with 38 degrees of freedom ,

i.e. P( t38>C ) = 0.0.25, C=?

display invttail(38, 0.025)

Exercise:

Calculate the probability of P(t > 1.66 ) for a sample of size 10.

What’s the 95th percentile of the t-distribution with a degree of freedom of 9?

Explanation / Answer

P(t>1.66) = 0.0656

95th percentile of the t-distribution with a degree of freedom of 9 is 1.833