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

# st: Re: How to compute sample size assuming a specificy accuracy in parameter estimation

 From "Joseph Coveney" <[email protected]> To <[email protected]> Subject st: Re: How to compute sample size assuming a specificy accuracy in parameter estimation Date Fri, 2 Mar 2012 17:03:58 +0900

```Tiago V. Pereira wrote:

I would like to know if there is a Stata package out there that computes
the sample size required to give a specific accuracy in the estimation of
the population parameter (assumed to be normally distributed).

For example, I would like to estimate the mean of a population having a
precision of 2 in my 95% confidence intervals. Precision here is the plus
and minus value used to create the confidence interval.

I have guesses on the population mean, standard deviation and know the
total population size.

I have checked -aipe-, -sampsi-, and others, but failed to find out a
specific package for that purpose.

Let me know if I am missing something when using them.

--------------------------------------------------------------------------------

If I understand you correctly, then you're looking for a sample size that gives
a 95% confidence half-interval of 2, assuming that the population standard
deviation equals some value.  In lieu of an analytical solution, couldn't you
just use simulation with something like the do-file below?  It uses an assumed
standard deviation of 10 for illustration.

I suppose you could do the simulation more formally, creating a population of
the known (finite) size and with the assumed standard deviation, storing it in a
file, and then sampling from it with various sample sizes.  I doubt that that
effort is worth it, though.

Joseph Coveney

version 11.2

clear *
set more off
set seed `=date("2012-03-02", "YMD")'

program define simem, rclass
version 11.2
syntax , n(integer) sd(real) halfwidth(real) ///
[level(real `c(level)')]

quietly drop _all
quietly set obs `n'
tempvar tmpvar0
generate double `tmpvar0' = rnormal(0, `sd')
quietly ci `tmpvar0', level(`level')
return scalar success = (r(ub) - r(mean)) <= `halfwidth'
end

forvalues n = 100(5)130 {
quietly simulate success = r(success), reps(1000) nodots: ///
simem , n(`n') sd(10) halfwidth(2)
summarize success, meanonly
display in smcl as text "N = `n'  Power = " %05.3f r(mean)
if 0.95 < r(mean) continue, break
}

exit

*
*   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/
```