Moon Joong
>
> 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.
expand 100 * rate
or (slightly safer, perhaps)
expand round(100 * rate,1)
Nick
[email protected]
*
* 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/