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 |
Ekaterina Hertog <ekaterina.hertog@sociology.ox.ac.uk> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: how to generate a variable where one third of values would be randomly assigned |

Date |
Mon, 12 Dec 2011 15:58:30 +0000 |

Dear Nick and Maarten, thank you, Ekaterina On 12/12/2011 15:46, Maarten Buis wrote:

On Mon, Dec 12, 2011 at 4:04 PM, Ekaterina Hertog wrote:I use stata 11 and I need to generate a variable where two thirds of observations (about 1300 obs) will be equal to 120 and the rest of the values are randomly assigned, but are all integers and less than 120.You did not specify the distribution from which you want to draw your random numbers, so I'll assume it to be a uniform distribution of integers between 0 and 120 (exclusive): *------------ begin example ----------- drop _all set obs 1950 gen x = cond( /// _n<=1300, /// 120, /// ceil(119*runiform()) /// ) *------------- end example ------------ 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/

* * 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: how to generate a variable where one third of values would be randomly assigned***From:*Ekaterina Hertog <ekaterina.hertog@sociology.ox.ac.uk>

**Re: st: how to generate a variable where one third of values would be randomly assigned***From:*Maarten Buis <maartenlbuis@gmail.com>

- Prev by Date:
**Re: st: how to generate a variable where one third of values would be randomly assigned** - Next by Date:
**Re: st: how to generate a variable where one third of values would be randomly assigned** - Previous by thread:
**Re: st: how to generate a variable where one third of values would be randomly assigned** - Index(es):