Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: estimate 95%CIs of the mean for different sample sizes


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: estimate 95%CIs of the mean for different sample sizes
Date   Thu, 10 Jun 2010 03:42:50 -0700 (PDT)

--- On Thu, 10/6/10, Miranda Kim wrote:
> I have data for a sample of 300 which is approximately
> normally distributed (slightly skewed). I would like to
> derive 95% confidence intervals around the estimate of the
> mean for sample sizes of 50, 80, 100, 150, and 400.
> Does anyone have any suggestions what command I can use to
> do this?

Here is one approach:

*----------------------- begin example ---------------------
program drop _all
*! version 1.0.0 MLB 10Jun2010
program define counterci, rclass
	syntax varname [if] [in],  ///
               n(numlist) [level(real `c(level)')]
	marksample touse
	qui sum `varlist' if `touse'
	tempname se df lev res
	matrix `res' = J(`: word count `n'', 2, .)
	matrix rownames `res' = `n'
	matrix colnames `res' = lb ub
	local i = 1
	foreach nobs of local n {
		scalar `se' = r(sd)/sqrt(`nobs')
		scalar `df' = `nobs' - 1
		scalar `lev' = (100 - `level') / 200
		matrix `res'[`i', 1] =                       /// 
                        r(mean) - invttail(`df',`lev')*`se', ///
		        r(mean) + invttail(`df',`lev')*`se' 
		local ++i
	}
	matlist `res'
	return matrix res = `res'
end

sysuse auto, clear
counterci gear_ratio, n(20 50 100)
*---------------------- end example --------------------------
(For more on examples I sent to the Statalist see: 
http://www.maartenbuis.nl/example_faq )


Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index