Statalist


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

Re: st: How to sample uniformly over a set of specific observations?


From   "Svend Juul" <SJ@SOCI.AU.DK>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: How to sample uniformly over a set of specific observations?
Date   Sun, 14 Oct 2007 21:03:34 +0200

Tiago wrote:
 
Suppose I have the following data set:
 
var1 var2 var3
0.5 0.5 0.25
0.4 0.4 0.16
0.3 0.4 0.12
0.8 0.4 0.32
0.4 0.2 0.08
 
In this sense, I would like to generate a new variable, say var4, which
may take one out of the 5 values presented (with equal probabilities).
I could not think about an easy way to do that using Stata when I have
several observations and, in some cases, repeated observations as well.
 
--------------------------------------------------
 
With three candidate variables:
 
   set seed 12345          // if you need to reproduce exactly
   generate x = uniform()
   generate var4 = var1
   replace var4 = var2 if x > 1/3
   replace var4 = var3 if x > 2/3
 
But you write about "the 5 values presented". You have five observations; 
three values per obervation, but 15 values in total. So I am not quite 
sure what you are looking for.
 
Hope this helps, anyway.
 
Svend
 
________________________________________________________ 
 
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6 
DK-8000 Aarhus C,  Denmark 
Phone, work:  +45 8942 6090 
Phone, home:  +45 8693 7796 
Fax:          +45 8613 1580 
E-mail:       sj@soci.au.dk 
_________________________________________________________ 

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index