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.
Nick
[email protected]
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)
}
summarize
exit
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:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/