Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Sampling from a uniform distribution - suggestion


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: Sampling from a uniform distribution - suggestion
Date   Wed, 20 Jun 2007 15:48:42 -0400

At 02:57 PM 6/20/2007, Jeph Herrin wrote -- in response to the question from Tiago Pereira :

How about:

  set obs 1000
  gen X =  uniform()*(60-10)+10
  replace X = uniform()*(3000-2000)+2000 if mod(_n,6)==0
Originally, I thought of the same solution. Later, I realized you can do it in one pass:

gen X = cond(mod(_n,6), uniform()*(60-10)+10 , uniform()*(3000-2000)+2000)

HTH
--David

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index