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

From |
"Moon Joong" <mj_52@hotmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: generate obs. according to some distribution |

Date |
Thu, 17 Apr 2003 18:15:36 -0400 |

Dear Nick,

Thanks a lot!

But can I 'generate' command in using 'expand' command? I tried but I can't do it.

Since in my dataset I have many variables like rate - rate1, rate2..., I need to generate new variables containg values of variable risk corresponding the distribution of each rate.

The dataset looks like this:

scale rate1 rate2 rate3 .....

1 .3 .5

2 .05 .1

3 .2 .1

4 .15 .1

5 .3 .2

So I need to create new variables (scale1, scale2, scale3,...) and make this each new variable that contains values of scale corresponding to each rate (rate1, rate2, rate3,...).

Thank you very much in advance. I really appreciate your help!

MoonJoong

From: "Nick Cox" <n.j.cox@durham.ac.uk> Reply-To: statalist@hsphsun2.harvard.edu To: <statalist@hsphsun2.harvard.edu> Subject: st: RE: generate obs. according to some distribution Date: Thu, 17 Apr 2003 22:33:25 +0100 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 n.j.cox@durham.ac.uk * * 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/

_________________________________________________________________

MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus

*

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

- Prev by Date:
**st: -regress- vs -logit- problem** - Next by Date:
**RE: st: Inverse Mills Ratio after MLOGIT** - Previous by thread:
**st: -regress- vs -logit- problem** - Next by thread:
**RE: st: IV and sample selection** - Index(es):

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