Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: generate obs. according to some distribution


From   "Moon Joong" <[email protected]>
To   [email protected]
Subject   st: generate obs. according to some distribution
Date   Thu, 17 Apr 2003 17:12:59 -0400

Dear Stata lovers:

Hi. I'm trying to generate a variable with obs. that takes certain vlues according to some distribution. I was wondering if anyone know any code/method to make the work easier and faster (since I have a lot). The example is following:

Let's say there are two variables - scale (that has certain values) and rate (rates corresponding to the values of scale that adds up 100%) - with 5 observation.

scale rate
1 .3
2 .05
3 .2
4 .15
5 .3

Now I want to generate and create a variable with, say, 100 observations that contain the values of scale (e.g., 1, 2, 3, 4, or, 5) according to the distribution of rate.

All I know is to do like this:

gen sum = sum(rate);

list sum;

sum
.3
.35
.55
.7
1

gen scale2 = 1 in 1/30;
replace scale2 = 2 in 31/35;
replace scale2 = 3 in 36/55;
replace scale2 = 4 in 56/70;
replace scale2 = 5 in 71/100;

And then I can get the variable called "scale2" that have 100 observation with values of scale according to the distribution of rate.

But since I have a lot of variables to create like that and the actual scale takes more than 5 values, it takes really long time.

Please let me know anyone know any easier way than the above method.

Thanks a lot in advance!!

Moonjoong



_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail

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