[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: RE: using drawnorm and by()??

From   Linn Renée Naper <>
To   <>
Subject   st: RE: RE: using drawnorm and by()??
Date   Tue, 11 Nov 2008 19:50:12 +0100

Thanks Nick, it makes sense.

-----Opprinnelig melding-----
Fra: [] På vegne av Nick Cox
Sendt: 11. november 2008 19:30
Emne: st: RE: using drawnorm and by()??

I haven't been following this thread closely, partly because I could not easily read earlier postings, but it is not obvious to me that you need to use -drawnorm- at all. 

. gen rndnorm = invnormal(uniform()) 

gives you a variable with random normal (Gaussian) deviates. Add means and multiply by standard deviations as desired. As the means and sds could differ by group, that is where the -by- element comes in. 


Linn Renée Naper

I typed the following commands in Stata 9.

set seed 123456
capture drop group_var
egen group_var=group(year)
sum group_var
forvalues i = 1(1) `r(max)' {
drawnorm x`i', m(0) sd(5)

Well, what this actually does is to produce seven variables with the given distribution (it is 7 years in my dataset). 
What I would like to do is to produce one random variable where the draw is done individually for each year, potentially also from a different distribution in different years(different m and sd for different years). (the dataset has hourly price variables and a year indicator following the prices).

I want to generate alternative group variables (not only by year, but also by seasons etc) in order to produce a random variable with different distribution for different parts of the dataset. So my question I guess is whether drawnorm in some way can be combined with by(), or if anyone has an alternative solution to this. Or do I have to do this manually for different parts of the data set, and then putting it all together in the end?

*   For searches and help try:

*   For searches and help try:

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