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

st: using drawnorm and by()??

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

Hi Statalist

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:

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