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]

From |
Maarten buis <maartenbuis@yahoo.co.uk> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Illustrate SRS in a graph |

Date |
Fri, 17 Sep 2010 08:02:40 +0000 (GMT) |

-------------------------- Maarten L. Buis Institut fuer Soziologie Universitaet Tuebingen Wilhelmstrasse 36 72074 Tuebingen Germany http://www.maartenbuis.nl -------------------------- --- On Thu, 16/9/10, Richard Moverare wrote: > I would like to illustrate the uncertainty of a SRS > (without replacement) by first creating a dataset with > one variable that identifies a number of different > groups in the population (N), e.g. 415 units in group A, > 634 units in group B, on so forth. Then I would like to > draw a number of samples from that population, e.g. 20 > different samples and get estimates for the proportion of > the population belonging to group A, B, ..., and the > confidence interval (95 percent) for those estimates. And > finally I would like to, in a graph, illustrate the true > population proportion and the 20 different samples with > their confidence intervals. This in order to illustrate > the uncertainty but also that the confidence interval > sometimes do not include the true population value. As I understand Simple Random Sampling, it would be sampling with replacement (but if the population is large compared to the sample that should not matter too much). *------------------- begin example -------------------- program drop _all program define sim, rclass drop _all set obs 10000 gen x = cond(_n <= 500, 1, /// cond(_n <= 5000, 2, 3)) sample 1 proportion x return scalar p = _b[x:1] return scalar lb = _b[x:1] - invttail(e(df_r),0.025)*_se[x:1] return scalar ub = _b[x:1] + invttail(e(df_r),0.025)*_se[x:1] end simulate p=r(p) lb=r(lb) ub=r(ub), reps(20) : sim gen sample = _n twoway scatter sample p || /// rcap lb ub sample, horizontal xline(.05) * * 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/

**References**:**st: Illustrate SRS in a graph***From:*Richard Moverare <richard.moverare@gmail.com>

- Prev by Date:
**Re: st: Illustrate SRS in a graph** - Next by Date:
**Re: st: save coefficients from a fixed effect regression** - Previous by thread:
**Re: Fwd: st: Illustrate SRS in a graph** - Next by thread:
**st: Comparing multinomial models in survey data** - Index(es):